转自:http://qingfeng825.iteye.com/blog/144704
list, set, map和props元素分别用来设置类型为List,Set,Map和Propertis的属性值。分别用来为bean传入集合值。
对应的spring的配置文件举例如下:
xml 代码
-
- <? xml version="1.0" encoding="gb2312" ?>
- <! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
- "http://www.springframework.org/dtd/spring-beans.dtd" >
- < beans >
- < bean id ="chinese" class ="Chinese" >
- < property name ="friends" >
- < list >
- < value > 张三 </ value >
- < value > 李四 </ value >
- < value > 王五 </ value >
- </ list >
- </ property >
- < property name ="score" >
- < map >
- < entry key ="数学" >
- < value > 60 </ value >
- </ entry >
- < entry key ="英语" >
- < value > 70 </ value >
- </ entry >
- < entry key ="语文" >
- < value > 80 </ value >
- </ entry >
- < entry key ="物理" >
- < value > 90 </ value >
- </ entry >
- < entry key ="化学" >
- < value > 95 </ value >
- </ entry >
- </ map >
- </ property >
- < property name ="basicInfo" >
- < props >
- < prop key ="身高" > 165 </ prop >
- < prop key ="体重" > 45kg </ prop >
- < prop key ="学历" > 大学本科 </ prop >
- </ props >
- </ property >
- < property name ="interest" >
- < set >
- < value > 唱歌 </ value >
- < value > 跳舞 </ value >
- < value > 书法 </ value >
- </ set >
- </ property >
- </ bean >
- </ beans >
对应的java类为:
java 代码
java 代码
-
public class Chinese implements People ...{ private List friends = new ArrayList(); private Map score = new HashMap(); private Properties basicInfo = new Properties(); private Set interest = new HashSet(); // 省略对应set方法 . }