zoukankan      html  css  js  c++  java
  • 使用集合方式注入IoC

    使用集合方式注入Ioc

    1.创建类

       //集合
        private String[] arrays;
        //list集合
        private List<Integer> lists;
        //map集合
        private Map<String,Object> maps;
        //set集合
        private Set<String> sets;
        //properties
        private Properties properties;

    2.编写applicationContext.xml配置文件

    <bean id="diTest" class="cn.spring.entity.DiTest">
            <property name="arrays">
                <array>
                    <value>zhangsa</value>
                </array>
            </property>
            <property name="lists"><!--为list集合赋值-->
                <list>
                    <value>14</value>
                    <value>15</value>
                </list>
            </property>
            <property name="sets"><!--为set集合赋值-->
                <set>
                    <value>山间的风</value>
                    <value>张三</value>
                </set>
            </property>
            <property name="maps"><!--为map集合赋值-->
                <map>
                    <entry key="姓名" value="山间的风"></entry>
                    <entry key="年龄" value="16"></entry>
                </map>
            </property>
            <property name="properties">
                <props>
                    <prop key="username">山间的风</prop>
                    <prop key="password">123456</prop>
                </props>
            </property>
      </bean>

    3.编写测试类

      ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
            DiTest diTest = (DiTest) context.getBean("diTest");
            System.out.println(diTest.getLists());

      

  • 相关阅读:
    团队项目-需求分析报告
    团队项目-选题报告
    第一次结对编程作业
    第一次个人编程作业
    软件工程作业(一)
    期末总结
    第04组 Beta冲刺(2/5)
    第04组 Beta冲刺(3/5)
    第04组 Beta冲刺(4/5)
    第04组 Beta冲刺(5/5)
  • 原文地址:https://www.cnblogs.com/szhhhh/p/11752232.html
Copyright © 2011-2022 走看看