具体项目如下(忽略service):
1.配置spring的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.wxy.dao.impl.BookDaoImpl">
<property name="array">
<array>
<value>180</value>
<value>190</value>
<value>200</value>
</array>
</property>
<property name="list">
<list>
<value>wfgang</value>
<value>kklove</value>
<value>kkecho</value>
</list>
</property>
<property name="set">
<set>
<value>wfgang</value>
<value>kklove</value>
<value>kkecho</value>
<value>kkecho</value>
</set>
</property>
<property name="map">
<map>
<entry key="country" value="China"/>
<entry key="province" value="Guangdong"/>
<entry key="city" value="Guangzhou"/>
</map>
</property>
<property name="properties">
<props>
<prop key="country">China</prop>
<prop key="province">Guangdong</prop>
<prop key="city">Guangzhou</prop>
</props>
</property>
</bean>
</beans>
2.编写实现接口:
package com.wxy.dao;
public interface BookDao {
public void save();
}
3.编写dao类:
package com.wxy.dao.impl;
import com.wxy.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;
}
@Override
public void save() {
System.out.println("save....");
}
@Override
public String toString() {
return "BookDaoImpl{" +
"array=" + Arrays.toString(array) +
", list=" + list +
", set=" + set +
", map=" + map +
", properties=" + properties +
'}';
}
}
4.编写测试类:
package com.wxy;
import com.wxy.dao.BookDao;
import com.wxy.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App1 {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
BookDao bookDao = (BookDao) ctx.getBean("bookDao");
bookDao.save();
System.out.println(bookDao.toString());
}
}
效果如下,可以看到参数已经全被传递了: