java Spring集合

在进行输入的时候一定要给属性配置set方法,因为不设置是注入不了的。

1.list

UserService.java

private ArrayList arr;
public ArrayList getArr() {
return arr;
}
public void setArr(ArrayList arr) {
this.arr = arr;
}

service.xml

 <bean name="userService" class="com.sun.service.UserService">
<property name="name" >
<value>sunxin</value>
</property>
<property name="arr">
<list>
<value>Tom</value>
<value>Jack</value>
<value>Jeson</value>
</list>
</property>
</bean>

2.map

private Map<String, Float> accounts;

    public void setAccounts(Map<String, Float> accounts) {
this.accounts = accounts;
}

service.xml

<beans>
<bean id="foo" class="com.sun.service.UserService">
<property name="accounts">
<map>
<entry key="one" value="9.99"/>
<entry key="two" value="2.75"/>
<entry key="six" value="3.99"/>
</map>
</property>
</bean>
</beans>
上一篇:多项式的运算以及插值


下一篇:OpenResty 操作cookies