spring如何装配各种集合范例

1 public class OrderServiceBean{
2     private Set<String> sets = new HashSet<String>();
3     private List<String> lists = new ArragList<String>();
4     private Properties properties = new Properties();
5     private Map<String,String> maps = new HashMap<String,String>();
6     
7     ...//省略属性的getter和setter方法
8 }

对Set集合进行装配(List集合装配方法类似):

1 <property name = "sets">
2     <set>
3         <value>第一个</value>
4         <value>第二个</value>
5         <value>第三个</value>
6     </set>
7 </property>

对Properties集合进行装配:

1 <property name="properties">
2     <props>
3         <prop key="key1">vlaue1</prop>
4         <prop key="key2">vlaue2</prop>
5         <prop key="key3">value3</prop>
6     <props>
7 </property>

对map集合进行装配:

1 <property name="maps">
2     <map>
3         <entry key="key-1" value="value-1"/>
4         <entry key="key-2" value="value-2"/>
5         <entry key="key-3" value="value-3"/>
6     </map>
7 </property>

 

posted @ 2015-05-27 13:05  别闹了  阅读(408)  评论(0编辑  收藏  举报