首页 > 代码库 > spring 中容器 map、set、list、property 的 bean 实例化
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实例化高级属性:
http://blog.csdn.net/lifeng_2009/article/details/5754658
spring 中容器 map、set、list、property 的 bean 实例化
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。