集合注入
有多个集合,我们可以通过配置文件来赋值
package com.itheima.dao.impl;
import com.itheima.dao.BookDao;
import java.util.*;
/**
* @Author: GenGen
* @Description: 6Ge
* @DateTime: 2022/10/3 16:09
**/
public class BookDaoImpl implements BookDao {
private int[] array;
private List<String> list;
private Set<String> set;
private Map<String,String> map;
private Properties properties;
public void setArray(int[] array) {
this.array = array;
}
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;
}
public void save() {
System.out.println("book dao save ...");
}
@Override
public String toString() {
return "BookDaoImpl{" +
"array=" + Arrays.toString(array) +
", list=" + list +
", set=" + set +
", map=" + map +
", properties=" + properties +
'}';
}
}
applicationContext1.xml配置
1、arrayList 用<array>
2、list 用<list>
3、set 用<set>
4、map 用
<map>
<entry key="" value=""></entry>
</map>
5、properties 用
<props>
<prop key="">a</prop>
</props>
<bean id="bookDao" class="com.itheima.dao.impl.BookDaoImpl ">
<property name="array">
<array>
<value>100</value>
<value>200</value>
<value>300</value>
</array>
</property>
<property name="list">
<list>
<value>a</value>
<value>b</value>
<value>c</value>
</list>
</property>
<property name="set">
<set>
<value>a</value>
<value>b</value>
<value>c</value>
<value>c</value>
</set>
</property>
<property name="map">
<map>
<entry key="1" value="a"></entry>
<entry key="2" value="b"></entry>
<entry key="3" value="c"></entry>
</map>
</property>
<property name="properties">
<props>
<prop key="1">a</prop>
<prop key="2">b</prop>
<prop key="3">c</prop>
</props>
</property>
</bean>
<bean id="bookService" class="com.itheima.service.impl.BookServiceImpl"/>