zoukankan      html  css  js  c++  java
  • spring数组注入

    数组注入

    public class MyCollection {
         private  String[]array;
         private List<String>list;
         private Set<String>set;
         Map<String,String>map;
         Properties properties;
        public String[] getArray() {
            return array;
        }
        public void setArray(String[] array) {
            this.array = array;
        }
        public List<String> getList() {
            return list;
        }
        public void setList(List<String> list) {
            this.list = list;
        }
        public Set<String> getSet() {
            return set;
        }
        public void setSet(Set<String> set) {
            this.set = set;
        }
        public Map<String, String> getMap() {
            return map;
        }
        public void setMap(Map<String, String> map) {
            this.map = map;
        }
        public Properties getProperties() {
            return properties;
        }
        public void setProperties(Properties properties) {
            this.properties = properties;
        }
    }

    <!--数组注入-->
     <bean id="array" class="cn.happy.spring03xmldi.MyCollection">
         <property name="array">
             <array>
                 <value>q</value>
                 <value>w</value>
                 <value>e</value>
                 <value>r</value>
             </array>
         </property>
     </bean>

    测试

    //数值注入
    public void test02(){
         ApplicationContext ct= new ClassPathXmlApplicationContext("applicationContextspring03xmldl.xml");
     MyCollection collection=(MyCollection)ct.getBean("array");
     System.out.println(collection.getArray()[1]);

    //map双列集合

    <!-- map 双列集合-->
    <bean id="map" class="cn.happy.spring03xmldi.MyCollection">
    <property name="map">
        <map>
            <!-- map中的每一项entry=key+value  -->
            <entry key="1" value="11"></entry>
            <entry key="2" value="22"></entry>
            <entry key="3">
                <value>33</value>
            </entry>
        </map>
    </property>
    </bean>

    测试

    public void test02(){
    ApplicationContext ct= new ClassPathXmlApplicationContext("applicationContextspring03xmldl.xml");
     MyCollection collection=(MyCollection)ct.getBean("map");
     System.out.println(collection.getMap());
    }

    结果:

     

  • 相关阅读:
    webapp开发绝对定位引发的问题
    git下配置github sshkey
    html5 filereader读取流注意事项
    神奇的负Margin
    泪奔的ie
    第二次作业-实践一 网络攻防环境的搭建
    20199115 2019-2020-2 《网络攻防实践》第一周作业
    《网络攻防实践》寒假作业
    C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
    getline()函数
  • 原文地址:https://www.cnblogs.com/wangdan123/p/7398842.html
Copyright © 2011-2022 走看看