ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
**1.com.nobb.bean.CollectionBean** ~~~ package com.nobb.bean; import java.util.*; public class CollectionBean { private List list; private Set set; private Object[] array; private Map map; private Properties properties; ~~~ **2.xml配置** ~~~ <bean name="car" class="com.nobb.bean.Car"> <property name="name" value="马萨拉蒂"></property> <property name="color" value="白色"></property> </bean> <bean name="cb" class="com.nobb.bean.CollectionBean"> <property name="list"> <!--定义为list--> <list> <value>tom</value> <value>jack</value> <ref bean="car"></ref> </list> </property> <property name="set"> <!--定义为set--> <set> <value>jack</value> <value>rose</value> <!--允许设置 但只显示一个--> <ref bean="car"></ref> <ref bean="car"></ref> </set> </property> <property name="array"> <!--定义为array--> <array> <value>tom</value> <value>jack</value> <ref bean="car"></ref> <ref bean="car"></ref> </array> </property> <property name="map"> <!-- 使用entry元素表示一个键值对 key:字符串类型键 key-ref:对象类型键 value:字符串类型值 value-ref:对象类型值 --> <map> <entry key="name" value="tom"/> <entry key="age" value="11"/> <entry key="car" value-ref="car"/> <entry key-ref="car" value-ref="car"/> </map> </property> <property name="properties"> <props> <prop key="driverClass">com.mysql.jdbc.Driver</prop> <prop key="username">root</prop> <prop key="password">123</prop> </props> </property> </bean> ~~~ **3.代码测试** ~~~ ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); CollectionBean cb = (CollectionBean)ac.getBean("cb"); System.out.println(cb); ~~~