spring2.0 标签

spring2.0中支持XML Schema同时继续支持dtd,这样在xml配置文件中可以使用dtdschema两种方式进行声明,示例如下:
spring2.0及之前版本均支持dtd声明:
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEbeansPUBLIC"-//SPRING//DTDBEAN//EN""http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
//这里是bean的配置
</beans>

spring2.0及以后版本支持schema声明:
<?xmlversion="1.0"encoding="UTF-8"?>
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
>
//这里是bean的配置
</beans>

spring2.0可以新增<util>标签进行扩充,使用<util:list><utilmap><util:set><util:properties>等标签可以取代并简化集合的配置,下面就4种标签分别举例说明:
在使用<util>标签之前首先要给xml配置文件中加入util的命名空间,增加后的spring配置文件头如下:
<?xmlversion="1.0"encoding="UTF-8"?>
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util
="http://www.springframework.org/schema/util"
xsi:schemaLocation
="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd"
>
……
</beans>

给上面的各种集合配置修改成<util >如下:
1list配置:
<!--配置一个人物角色-->
<beanid="role"class="spring.chapter2.setDemo.Role">
<propertyname="name"value="Mary"/>
<propertyname="health"value="100"/>
<propertyname="goods">
<list>
<refbean="medicine"/>
<refbean="medicine1"/>
</list>
</property>
</bean>

修改成<util:list>配置:
<!--配置一个人物角色-->
<util:listid="medicinelist">
<refbean="medicine"/>
<refbean="medicine1"/>
</util:list>
<beanid="role"class="spring.chapter2.setDemo.Role">
<propertyname="name"value="Mary"/>
<propertyname="health"value="100"/>
<propertyname="goods"ref="medicinelist">

<util:list>标签可以使用list-class来指定的list作为使用的集合对象:
<util:list id="medicinelist" list-class="java.util.ArrayList">
2set配置
<!--配置一个人物角色-->
<beanid="role"class="spring.chapter2.setDemo.Role">
<propertyname="name"value="Mary"/>
<propertyname="health"value="100"/>
<propertyname="goods">
<set>
<refbean="medicine"/>
<refbean="medicine1"/>
</set>
</property>
</bean>
修改成<util:set>配置:
<!--配置一个人物角色-->
<util:setid="medicineset">
<refbean="medicine"/>
<refbean="medicine1"/>
</util:set>
<beanid="role"class="spring.chapter2.setDemo.Role">
<propertyname="name"value="Mary"/>
<propertyname="health"value="100"/>
<propertyname="goods"ref="medicineset"/>
</bean>
<util:set>

标签也可以使用set-class来指定使用的集合容器对象:
<util:set id="medicineset" set-class="java.util.TreeSet">
3map配置:
<!--配置一个人物角色-->
<beanid="role"class="spring.chapter2.setDemo.Role">
<propertyname="name"value="Mary"/>
<propertyname="health"value="100"/>
<propertyname="goods">
<map>
<entrykey="key1">
<value>小药丸</value>
</entry>
<entrykey="key2">
<value>大药丸</value>
</entry>

</map>
</property>
</bean>

修改成<util:map>配置:
<!--配置一个人物角色-->
<util:mapid="medicinemap">
<entrykey="key1"value="小药丸"/>
<entrykey="key2"value="大药丸"/>
</util:map>
<beanid="role"class="spring.chapter2.setDemo.Role">
<propertyname="name"value="Mary"/>
<propertyname="health"value="100"/>
<propertyname="goods"ref="medicinemap"/>
</bean>

可以使用map-class来指定使用的集合对象
4properties配置:
<!--配置一个人物角色-->
<beanid="role"class="spring.chapter2.setDemo.Role">
<propertyname="name"value="Mary"/>
<propertyname="health"value="100"/>
<propertyname="goods">
<props>
<propkey="key1">小药丸</prop>
<propkey="key1">大药丸</prop>
</props>
</property>
</bean>

修改成<util:properties>配置如下:
<!--配置一个人物角色-->
<util:propertiesid="medicineprops">
<propkey="key1"value="小药丸"/>
<propkey="key1"value="大药丸"/>
</util:properties>
<beanid="role"class="spring.chapter2.setDemo.Role">
<propertyname="name"value="Mary"/>
<propertyname="health"value="100"/>
<propertyname="goods"ref="medicineprops"/>
</bean>

<util:properties>可以使用location标签来载入外部properties文件:
<util:properties id="medicineprops" location="classpath:config.properties"/>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值