五种集合
1.list;
2.array;
3.set;
4.map;
5.props;
新建了Colection.java实体类
Collection.java
package com.bb.entity;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class Collection {
private List<String> list;
private String[] array;
private Set<String> set;
private Map<String,String> map;
private Properties props;
public Collection() {
}
public Collection(List<String> list, String[] array, Set<String> set, Map<String, String> map, Properties props) {
this.list = list;
this.array = array;
this.set = set;
this.map = map;
this.props = props;
}
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public String[] getArray() {
return array;
}
public void setArray(String[] array) {
this.array = array;
}
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 getProps() {
return props;
}
public void setProps(Properties props) {
this.props = props;
}
}
applicationContext.xml
<!-- 各种集合的依赖注入,使用<property>标签-->
<bean id="collection" class="com.bb.entity.Collection">
<property name="list" >
<list>
<value>Dota-list</value>
<value>Wow-list</value>
<value>Lol-list</value>
</list>
</property>
<property name="array">
<array>
<value>dota-array</value>
<value>wow-array</value>
<value>lol-array</value>
</array>
</property>
<property name="set">
<set>
<value>dota-set</value>
<value>wow-set</value>
<value>lol-set</value>
</set>
</property>
<property name="map">
<map>
<entry key="1" value="dota-map"></entry>
<entry key="2" value="wow-map"></entry>
<entry key="3" value="lol-map"></entry>
</map>
</property>
<property name="props">
<props>
<prop key="1">dota-props</prop>
<prop key="2">wow-props</prop>
<prop key="3">lol-props</prop>
</props>
</property>
</bean>
TestSpring.java
//各种集合的依赖注入
public static void collection(){
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Collection collection = (Collection)context.getBean("collection");
System.out.println("list:"+collection.getList());
System.out.println("array:"+collection.getArray());
System.out.println("set:"+collection.getSet());
System.out.println("map:"+collection.getMap());
System.out.println("props:"+collection.getProps());
}
结果输出:
list:[Dota-list, Wow-list, Lol-list]
array:[Ljava.lang.String;@3e57cd70
set:[dota-set, wow-set, lol-set]
map:{1=dota-map, 2=wow-map, 3=lol-map}
props:{3=lol-props, 2=wow-props, 1=dota-props}