spring 中容器 map、set、list、property 的 bean 实例化
参考:http://www.kaifajie.cn/spring/9966.html
<bean id="fieldMap" class="org.springframework.beans.factory.config.MapFactoryBean"> <property name="sourceMap"> <map> <entry key="title" value-ref="obj"></entry> <entry key="reserve_price" value-ref="double"></entry> <entry key="auction_status" value-ref="obj"></entry> <entry key="quantity" value-ref="obj"></entry> <entry key="options" value-ref="obj"></entry> <entry key="spu_id" value-ref="obj"></entry> <entry key="sold_quantity" value-ref="obj"></entry> <entry key="features" value-ref="obj"></entry> <entry key="category" value-ref="obj"></entry> <entry key="user_id" value-ref="obj"></entry> <entry key="auction_id" value-ref="obj"></entry> <entry key="gmt_modified" value-ref="date"></entry> <entry key="pict_url" value-ref="obj"></entry> <entry key="sync_version" value-ref="obj"></entry> </map> </property> </bean> <bean id="date" class="java.lang.Class" factory-method="forName"> <constructor-arg value="java.util.Date"/> </bean> <bean id="double" class="java.lang.Class" factory-method="forName"> <constructor-arg value="java.lang.Double"/> </bean> <bean id="obj" class="java.lang.Class" factory-method="forName"> <constructor-arg value="java.lang.Object"/> </bean>
其它容器:
http://www.blogjava.net/amigoxie/archive/2007/02/16/100049.html
< beans > < bean id ="chinese" class ="Chinese" > < property name ="friends" > < list > < value > 张三 </ value > < value > 李四 </ value > < value > 王五 </ value > </ list > </ property > < property name ="score" > < map > < entry key ="数学" > < value > 60 </ value > </ entry > < entry key ="英语" > < value > 70 </ value > </ entry > < entry key ="语文" > < value > 80 </ value > </ entry > < entry key ="物理" > < value > 90 </ value > </ entry > < entry key ="化学" > < value > 95 </ value > </ entry > </ map > </ property > < property name ="basicInfo" > < props > < prop key ="身高" > 165 </ prop > < prop key ="体重" > 45kg </ prop > < prop key ="学历" > 大学本科 </ prop > </ props > </ property > < property name ="interest" > < set > < value > 唱歌 </ value > < value > 跳舞 </ value > < value > 书法 </ value > </ set > </ property > </ bean > </ beans >
public class Chinese implements People { private List friends = new ArrayList(); private Map score = new HashMap(); private Properties basicInfo = new Properties(); private Set interest = new HashSet(); // 省略对应set方法 . }
附上bean实例化高级属性:
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。