zoukankan      html  css  js  c++  java
  • Spring中的p标签(转)

    Spring的p标签是基于XML Schema的配置方式,目的是为了简化配置方式。

    在XML文件头部添加xmlns:p="http://www.springframework.org/schema/p"即可使用。

    例如:

    类Person

    1. public class Person  
    2. {  
    3.   private int age;  
    4.   private Tool tool;  
    5.   public void setAge(int age)  
    6.   {  
    7.      this.age=age;  
    8.   }  
    9.   public void setTool(Tool tool)  
    10.   {  
    11.      this.tool=tool;  
    12.   }  
    13. 其余代码省略  
    14. ......  
    15. }  

    原本的bean配置为

    1. <?xml version="1.0" encoding="GBK"?>  
    2. <beans xmlns="http://www.springframework.org/schema/beans"  
    3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    4.     xsi:schemaLocation="http://www.springframework.org/schema/beans   
    5.     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">  
    6.     <bean id="person" class="com.myclass.Person">  
    7.         <property name="age" value="21"/>  
    8.         <property name="tool" ref="tool"/>  
    9.     </bean>  
    10. </beans>  


    使用P标签的配置为

    1. <?xml version="1.0" encoding="GBK"?>  
    2. <beans xmlns="http://www.springframework.org/schema/beans"  
    3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    4.     xmlns:p="http://www.springframework.org/schema/p"  
    5.     xsi:schemaLocation="http://www.springframework.org/schema/beans   
    6.     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">  
    7.     <bean id="person" class="com.myclass.Person" p:age="21" p:tool-ref="tool"/>  
    8. </beans>  

    tool之后添加"-ref"后缀表示是对另外一个bean的引用。

  • 相关阅读:
    __attribute__ 总结
    linux文件夹打包命令
    学习ARM的一些基本知识,个人整理
    备忘录之 —— .bashrc(IC工具篇)
    GitHub的基本使用
    02: SocketServer服务
    01: socket模块
    08: python基础练习题
    07: 高阶函数&异常处理
    06: 面向对象
  • 原文地址:https://www.cnblogs.com/cornucopia/p/4504009.html
Copyright © 2011-2022 走看看