private String[]arrays; private List; private Setset; private Mapmap; private Propertiesprop;
以上提供标准的get set toString;
ioc.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="obj" class="java.lang.Object" />
<bean id="stu" class="com.qfedu.pojo.Student">
<property name="sid" value="08" />
<property name="name" value="zhangsan" />
<property name="sex" value="true" />
<property name="score" value="100" />
<property name="age" value="18" />
</bean>
<bean id="myColl" class="com.qfedu.ioc.MyColl">
<property name="arrays">
<array>
<value>java</value>
<value>java</value><!--允许重复-->
<value>html5</value>
<value>python</value>
<value>testing</value>
</array>
</property>
<property name="list">
<list>
<value>zhouxingxing</value>
<value>zhouxingxing</value><!--允许重复-->
<value>9527</value>
<ref bean="obj" />
<ref bean="stu" />
</list>
</property>
<property name="set">
<set>
<value>suwukong</value>
<value>suwukong</value> <!--该值不会被加入,已经存在-->
<value>zhubajie</value>
<value>tangtang</value>
<value>shaheshang</value>
</set>
</property>
<property name="map">
<map>
<entry key="jack" value="杰克"/> <!--添加方法返回为null-->
<entry key="jack" value="杰克2"/> <!--添加方法返回为杰克-->
<entry key="rose" value="肉丝"/> <!--添加方法返回为null-->
<entry key="rose" value="null"/> <!--添加方法返回为肉丝,map里允许空value-->
<entry key="null" value="肉丝"/> <!--map允许空key-->
<entry key="null" value="null"/> <!--map里允许key和value同时为null,该方法返回肉丝-->
</map>
</property>
<property name="prop">
<props>
<prop key="url">jdbc:mysql://localhost:3306/hello</prop>
<prop key="driver">com.mysql.jdbc.Driver</prop>
<prop key="username">root</prop>
<prop key="password">123456</prop>
</props>
</property>
</bean>
</beans>
测试类:
package com.qfedu.ioc;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestCollection {
@Test
public void test(){
ApplicationContext ac = new ClassPathXmlApplicationContext("com/qfedu/ioc/ioc.xml");
MyColl mc = ac.getBean("myColl", MyColl.class);
System.out.println(mc);
}
}