创建一个实体
package wzf.user;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class jihe {
//常见的集合
private String[] arrayData;//数组
private List<String> listData;//list数组
private Set<String> setData;
private Map<String,String> mapData;
private Properties propsData;
@Override
public String toString() {
return "jihe [\narrayData=" + Arrays.toString(arrayData) + ", \nlistData=" + listData + ", \nsetData=" + setData
+ ",\n mapData=" + mapData + ",\n propsData=" + propsData + "\n]";
}
public String[] getArrayData() {
return arrayData;
}
public void setArrayData(String[] arrayData) {
this.arrayData = arrayData;
}
public List<String> getListData() {
return listData;
}
public void setListData(List<String> listData) {
this.listData = listData;
}
public Set<String> getSetData() {
return setData;
}
public void setSetData(Set<String> setData) {
this.setData = setData;
}
public Map<String, String> getMapData() {
return mapData;
}
public void setMapData(Map<String, String> mapData) {
this.mapData = mapData;
}
public Properties getPropsData() {
return propsData;
}
public void setPropsData(Properties propsData) {
this.propsData = propsData;
}
}
在编写app4.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">
<!--
数组
list
set
map
properties
普通数据value
引用数据ref
-->
<bean id="jihe" class="wzf.user.jihe">
<property name="arrayData">
<array>
<value>a</value>
<value>b</value>
<value>c</value>
</array>
</property>
<property name="listData">
<array>
<value>a</value>
<value>b</value>
<value>c</value>
</array>
</property>
<property name="setData">
<array>
<value>a</value>
<value>b</value>
<value>c</value>
</array>
</property>
<property name="mapData">
<map>
<entry key="A" value="a"></entry>
<entry key="B" value="b"></entry>
<entry key="C" value="c"></entry>
<entry >
<key><value>D</value></key>
<value>d</value>
</entry>
</map>
</property>
<property name="propsData">
<props>
<prop key="A">a</prop>
<prop key="B">b</prop>
<prop key="C">c</prop>
</props>
</property>
</bean>
</beans>
编写测试类
@Test
public void app4() {
String xml="app4.xml";
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(xml);
jihe j= (jihe) applicationContext.getBean("jihe");
System.out.println(j);
}
欢迎大家补充,相互学习,共同进步!