spring_spring集合装配注入
package com.bjsxd.dao.impl;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.bjsxd.dao.UserDao;
import com.bjsxd.model.User;
public class UserDaoImpl implements UserDao {
private Set<String> sets;
private List<String> lists;
private Map<String, String> maps;
public Set<String> getSets() {
return sets;
}
public void setSets(Set<String> sets) {
this.sets = sets;
}
public List<String> getLists() {
return lists;
}
public void setLists(List<String> lists) {
this.lists = lists;
}
public Map<String, String> getMaps() {
return maps;
}
public void setMaps(Map<String, String> maps) {
this.maps = maps;
}
@Override
public void save(User user) {
System.out.println("user save!");
}
}
<?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 name="userDaoImpl" class="com.bjsxd.dao.impl.UserDaoImpl">
<property name="sets">
<set>
<value>1</value>
<value>2</value>
</set>
</property>
<property name="lists">
<list>
<value>1</value>
<value>2</value>
<value>3</value>
</list>
</property>
<property name="maps">
<map>
<entry key="1" value="张三" />
<entry key="2" value="李四" />
<entry key="3" value="王五" />
<entry key="4" value="赵六" />
</map>
</property>
</bean>
<!-- <bean id="userService" class="com.bjsxd.service.UserService"> <property
name="userDao" ref="userDaoImpl" /> </bean> -->
<bean id="userService" class="com.bjsxd.service.UserService">
<constructor-arg>
<ref bean="userDaoImpl" />
</constructor-arg>
</bean>
</beans>
伪案例:
<bean id="moreComplexObject" class="example.ComplexObject">
<!-- results in a setAdminEmails(java.util.Properties) call -->
<property name="adminEmails">
<props>
<prop key="administrator">administrator@example.org</prop>
<prop key="support">support@example.org</prop>
<prop key="development">development@example.org</prop>
</props>
</property>
<!-- results in a setSomeList(java.util.List) call -->
<property name="someList">
<list>
<value>a list element followed by a reference</value>
<ref bean="myDataSource" />
</list>
</property>
<!-- results in a setSomeMap(java.util.Map) call -->
<property name="someMap">
<map>
<entry key="an entry" value="just some string"/>
<entry key ="a ref" value-ref="myDataSource"/>
</map>
</property>
<!-- results in a setSomeSet(java.util.Set) call -->
<property name="someSet">
<set>
<value>just some string</value>
<ref bean="myDataSource" />
</set>
</property>
</bean>
还没有评论,来说两句吧...