✨案例
✨BookDao接口
package com.jkj.dao;
public interface BookDao {
void save();
}
✨BookDaoImpl实现类
package com.jkj.dao.impl;
import com.jkj.dao.BookDao;
import java.util.*;
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("BookDao...");
System.out.println("遍历数组:"+ Arrays.toString(array));
System.out.println("遍历List:"+list);
System.out.println("遍历Set:"+set);
System.out.println("遍历Map:"+map);
System.out.println("遍历Properties:"+properties);
}
}
✨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="bookDao" class="com.jkj.dao.impl.BookDaoImpl">
<property name="array">
<array>
<value>12</value>
<value>14</value>
<value>16</value>
</array>
</property>
<property name="list">
<list>
<value>小马哥</value>
<value>Tom</value>
<value>小飞侠</value>
</list>
</property>
<property name="set">
<set>
<value>Cat</value>
<value>Cat</value>
<value>Tom</value>
<value>Jack</value>
</set>
</property>
<property name="map">
<map>
<entry key="1" value="34"></entry>
<entry key="2" value="小飞侠"></entry>
<entry key="3" value="Rack"></entry>
</map>
</property>
<property name="properties">
<props>
<prop key="1">科比</prop>
<prop key="2">詹姆斯</prop>
<prop key="3">哈登</prop>
</props>
</property>
</bean>
</beans>
✨Test测试类
import com.jkj.dao.BookDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
BookDao bookDao = (BookDao) context.getBean("bookDao");
bookDao.save();
}
}
/*
BookDao...
遍历数组:[12, 14, 16]
遍历List:[小马哥, Tom, 小飞侠]
遍历Set:[Cat, Tom, Jack]
遍历Map:{1=34, 2=小飞侠, 3=Rack}
遍历Properties:{3=哈登, 2=詹姆斯, 1=科比}
*/