spring-04
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring-04相关的知识,希望对你有一定的参考价值。
集合注入
Member
1 public class Member { 2 private List<String> names ; 3 private Set<String> emails ; 4 private Map<String,String> tels ; 5 private Properties infos ; 6 7 public Properties getInfos() { 8 return infos; 9 } 10 11 public void setInfos(Properties infos) { 12 this.infos = infos; 13 } 14 15 public List<String> getNames() { 16 return names; 17 } 18 19 public void setNames(List<String> names) { 20 this.names = names; 21 } 22 23 public Set<String> getEmails() { 24 return emails; 25 } 26 27 public void setEmails(Set<String> emails) { 28 this.emails = emails; 29 } 30 31 public Map<String, String> getTels() { 32 return tels; 33 } 34 35 public void setTels(Map<String, String> tels) { 36 this.tels = tels; 37 } 38 39 @Override 40 public String toString() { 41 return "Member [names=" + names + ", emails=" + emails + ", tels=" + tels + ", infos=" + infos + "]"; 42 } 43 }
applicationContext.xml
在默认情况下会用ArrayList为List接口实例化。
LinkedHashSet实例化Set 。结合了List的顺序保存,和Set的不容许重复。
<bean id="member" class="cn.mldn.vo.Member" > <property name="names" > <!-- 这里不写value-type 也可以正确为集合设置内容 --> <list value-type="java.lang.String"> <value>Smith</value> <value>Tony</value> <value>Smith</value> </list> </property> <property name="emails"> <set> <value>[email protected]</value> <value>[email protected]</value> <value>[email protected]</value> <value>[email protected]</value> </set> </property> <property name="tels"> <map> <entry key="110" value="公安" /> <entry> <key><value>120</value></key> <value>急救</value> </entry> </map> </property> <property name="infos"> <props> <prop key="mldn">www.mldn.cn</prop> <prop key="asdf">asdfasdfas</prop> </props> </property> </bean>
以上是关于spring-04的主要内容,如果未能解决你的问题,请参考以下文章