码迷,mamicode.com
首页 > 编程语言 > 详细

spring-04

时间:2018-11-05 21:57:03      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:his   cat   mes   style   return   type   info   span   name   

集合注入

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>test_123@qq.com</value>
                    <value>xiaohuang@163.com</value>
                    <value>bupbi@qq.com</value>
                    <value>bupbi@qq.com</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

标签:his   cat   mes   style   return   type   info   span   name   

原文地址:https://www.cnblogs.com/blog-747674599/p/9911742.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!