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.****.net/lifeng_2009/article/details/5754658



上一篇:004 01 Android 零基础入门 01 Java基础语法 01 Java初识 04 Java程序的结构


下一篇:Python实验考试