1.创建实体类
public class Department {
private String name;
private String [] arr;
private List<Emp> list;
private Set<Emp> set;
private Map<String,Emp> map;
private Properties pp;
......
}
2.对applicationContext.xml进行配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="department" class="com.xxx.xxx.Department">
<property name="name" value="财务部"/>
<property name="arr">
<list>
<value>小明</value>
<value>小明</value>
</list>
</property>
<property name="list">
<list>
<ref bean="emp2" />
<ref bean="emp1"/>
</list>
</property>
<property name="set">
<set>
<ref bean="emp1" />
<ref bean="emp2"/>
</set>
</property>
<property name="map">
<map>
<entry key="11" value-ref="emp1" />
<entry key="22" value-ref="emp2"/>
<entry key="22" value-ref="emp1"/>
</map>
</property>
<property name="pp">
<props>
<prop key="pp1">abcd</prop>
<prop key="pp2">hello</prop>
</props>
</property>
</bean>
<bean id="emp1" class="com.xxx.xxx.Emp">
<property name="name" value="北京"/>
<property name="id" value="1"/>
</bean>
<bean id="emp2" class="com.xxx.xxx.Emp">
<property name="name" value="天津"/>
<property name="id" value="2"/>
</bean>
</beans>
3.通过api获取对应属性
public void test(){
ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
Department department=(Department) ac.getBean("department");
arr/list/set/map/pp = department.getXXX();
}