zoukankan      html  css  js  c++  java
  • Spring集合装配

     1 package com.bxw.demo;
     2 import java.util.List;
     3 import java.util.Map;
     4 import java.util.Set;
     5 
     6 
     7 public class Demo {
     8     private Set<String> set;
     9     private Map<String, String> map;
    10     private List<String> list;
    11     public Set<String> getSet() {
    12         return set;
    13     }
    14     public void setSet(Set<String> set) {
    15         this.set = set;
    16     }
    17     public Map<String, String> getMap() {
    18         return map;
    19     }
    20     public void setMap(Map<String, String> map) {
    21         this.map = map;
    22     }
    23     public List<String> getList() {
    24         return list;
    25     }
    26     public void setList(List<String> list) {
    27         this.list = list;
    28     }
    29     
    30     @Override
    31     public String toString() {
    32         return "set:"+set.size()+"
    "+"map:"+map.size()+"
    "+"list:"+list.size();
    33     }
    34 }
    Demo.java

    配置文件:

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans
     3     xmlns="http://www.springframework.org/schema/beans"
     4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     5     xmlns:p="http://www.springframework.org/schema/p"
     6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
     7 <bean name="demo" class="com.bxw.demo.Demo">
     8     <property name="set">
     9         <set>
    10             <value>1</value>
    11             <value>2</value>    
    12         </set>
    13     </property>
    14     <property name="map">
    15         <map>
    16             <entry key="1" value="1"></entry>
    17             <entry key="2" value="2"></entry>
    18             <entry key="3" value="3"></entry>
    19         </map>
    20     </property>
    21     <property name="list">
    22         <list>
    23             <value>1</value>
    24             <value>2</value>
    25             <value>3</value>
    26         </list>
    27     </property>
    28 </bean>
    29 
    30 </beans>
    applicationContext.xml

    测试:

     1 package com.bxw.test;
     2 import org.springframework.context.ApplicationContext;
     3 import org.springframework.context.support.ClassPathXmlApplicationContext;
     4 
     5 import com.bxw.demo.Demo;
     6 
     7 
     8 public class DemoTest {
     9     public static void main(String[] args) {
    10         ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
    11         Demo dd = (Demo) ac.getBean("demo");
    12         System.out.println(dd.toString());
    13     }
    14 }
    DemoTest.java

    运行结果:

  • 相关阅读:
    CSS盒模型
    js异步加载——defer和async的区别
    href和src的区别
    JS中Null与Undefined的区别
    浅谈Web Workers
    flex布局学习笔记
    Promise
    js数组类型检测
    JavaScript中的遍历
    Autocomplete
  • 原文地址:https://www.cnblogs.com/popcornya/p/6810242.html
Copyright © 2011-2022 走看看