————————————————————————————————————————————————————
最近在工作上用上了Command模式,但在Spring上使用Command模式由于不能在代码中直接使用new,否则就不能使用其他配置在Spring中的DAO,所以需要把Command配置到Spring中。以下是一个
<?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-2.0.xsd">
<!-- Construct List -->
<bean id="nameList" class="java.util.ArrayList">
<constructor-arg>
<list>
<value>liuyu</value>
</list>
</constructor-arg>
</bean>
<!-- Construct Map -->
<bean id="nameMap" class="java.util.HashMap">
<constructor-arg>
<map>
<entry key="liuyu" value-ref="nameList" />
</map>
</constructor-arg>
</bean>
<!-- Inject List and Map -->
<bean id="myDemo" class="spring.inject.demo.MyDemo">
<property name="nameList">
<ref local="nameList" />
</property>
<property name="nameMap">
<ref local="nameMap" />
</property>
</bean>
</beans>
public class MyDemo {
private List<String> nameList = null;
private Map<String, List<String>> nameMap = null;
public List<String> getNameList() {
return nameList;
}
public void setNameList(List<String> nameList) {
this.nameList = nameList;
}
public Map<String, List<String>> getNameMap() {
return nameMap;
}
public void setNameMap(Map<String, List<String>> nameMap) {
this.nameMap = nameMap;
}
}
傲轩游戏网