标签:
在spring 的配置中共用属性模版时,使用parent
=
‘parentBean‘,如果parentBean里面有个List集合属性,子类还想在这个List里面添加元素,这是怎么办呢?
public class Person { private List<Address> addresses; .. }
<bean name=‘basePerson‘ class=‘Person‘ abstract=‘true‘> <property name=‘addresses‘> <list> <bean class=‘Address‘ p:street=‘Street1‘ p:state=‘State1‘ p:zip=‘001‘></bean> <bean class=‘Address‘ p:street=‘Street2‘ p:state=‘State2‘ p:zip=‘002‘></bean> <bean class=‘Address‘ p:street=‘Street3‘ p:state=‘State3‘ p:zip=‘003‘></bean> </list> </property> </bean>
<bean name=‘person1‘ class=‘Person‘ parent=‘basePerson‘> <property name=‘addresses‘> <list merge=‘true‘> <bean class=‘Address‘ p:street=‘Street4‘ p:state=‘State4‘ p:zip=‘004‘></bean> </list> </property> </bean>
注意<list merge="true">中有个merge属性,这一规则同样适用于<set/>, <map/> and <props/>
标签:
原文地址:http://my.oschina.net/u/2007041/blog/395017