1 可使用<list> <map> <set>等来配置集合属性
2 List <!-- 配置List属性 --> <bean id="person3" class="com.kejian.spring.bean.collectionbean.PersonForList"> <property name="name" value="Peter"></property> <property name="age" value="30"></property> <property name="cars"> <list> <ref bean="car1"/> <ref bean="car2"/> </list> </property> </bean>
3 Map <!-- 配置Map属性 --> <bean id="person4" class="com.kejian.spring.bean.collectionbean.PersonForMap"> <property name="name" value="Mike"></property> <property name="age" value="35"></property> <property name="cars"> <map> <entry key="ACar" value-ref="car1"></entry> <entry key="BCar" value-ref="car2"></entry> </map> </property> </bean>
4 Props:配置properties <!-- 通过props来配置properties --> <bean id="datasource" class="com.kejian.spring.bean.collectionbean.Datasource"> <property name="properties"> <props> <prop key="user">root</prop> <prop key="password">root</prop> <prop key="url">jdbc:mysql.///test</prop> <prop key="driver">jdbc.mysql.driver</prop> </props> </property> </bean>
5 单独配置集合bean:需引入Util shema <!-- 单独配置集合 --> <util:list id="cars"> <ref bean="car1"/> <ref bean="car2"/> </util:list>
6 使用p shema更快捷配置bean属性:需引入p shema <!-- 通过p命名空间来配置bean属性 --> <bean id="person5" class="com.kejian.spring.bean.collectionbean.PersonForList" p:name="Jack" p:age="22" p:cars-ref="cars">
</bean> (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|