集合注入
集合注入
包括数组、List、Set、Map和Property, 用于数据的初始化(不常用)
public class BookDaoImpl implements BookDao {
private int[] arr;
private List<String> list;
private Set<String> set;
private Map<String, String> map;
private Properties properties;
public void setArr(int[] arr) {
this.arr = arr;
}
public void setList(List<String> list) {
this.list = list;
}
public void setSet(Set<String> set) {
this.set = set;
}
public void setMap(Map<String, String> map) {
this.map = map;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
@Override
public void save() {
System.out.println("book dao save...");
System.out.println("遍历数组:" + Arrays.toString(arr));
System.out.println("遍历List:" + list);
System.out.println("遍历Set:" + set);
System.out.println("遍历Map:" + map);
System.out.println("遍历Properties" + properties);
}
}
<?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="bookDao" class="com.charley.dao.impl.BookDaoImpl">
<!--注入数组-->
<property name="arr">
<array>
<value>100</value>
<value>200</value>
<value>300</value>
</array>
</property>
<!--注入list-->
<property name="list">
<list>
<value>itcast</value>
<value>itheima</value>
<value>boxuegu</value>
<value>boxuegu</value>
</list>
</property>
<!--注入set-->
<property name="set">
<set>
<value>itcast</value>
<value>itheima</value>
<value>boxuegu</value>
<value>boxuegu</value>
</set>
</property>
<!--注入map-->
<property name="map">
<map>
<entry key="country" value="china"/>
<entry key="province" value="henan"/>
<entry key="city" value="kaifeng"/>
</map>
</property>
<!--注入properties-->
<property name="properties">
<props>
<prop key="country">china</prop>
<prop key="province">henan</prop>
<prop key="city">kaifeng</prop>
</props>
</property>
</bean>
</beans>