spring中集合的配置
<?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-3.1.xsd "> <bean id="user" class="july.wild.domain.User"> <property name="name" value="guosai"></property> <property name="age" value="25"></property> <property name="birthday" > <bean factory-bean="birthday" factory-method="parse"> <constructor-arg value="1995-01-21"></constructor-arg> </bean> </property> <!-- 使用ref来指向对应的对象--> </bean> <bean id="birthday" class="java.text.SimpleDateFormat"> <constructor-arg name="pattern" value="yyyy-mm-dd"></constructor-arg> </bean> <bean id="nowtime" class="java.util.Date"></bean> <bean id="userDaoImpl" class="july.wild.Dao.Impl.UserDaoImpl"></bean> <!-- 获取userdao的实现类--> <!--关于集合的实现--> <bean id="collection" class="july.wild.domain.CollectionTest"> <property name="myarray" > <array> <value>guosai</value> <value>lifei</value> <value>panli</value> <value>chenqiong</value> </array> </property> <property name="mylist"> <list> <value>aaa</value> <value>bbb</value> <value>ccc</value> </list> </property> <property name="mymap"> <map> <entry key="guosai" value="man"></entry> <entry key="user" value-ref="user"></entry> <!--是哦也能够value_ref来指明需要引用的对象id--> <entry key="huanglun" > <list> <value>25</value> <value>tianmen</value> <value>xueba</value> <value>brother</value> </list> </entry> </map> </property> </bean> </beans>
<?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-3.1.xsd "> <!-- <bean id="AccountImpl" class="july.wild.ServiceImpl.AccountImpl"></bean>--> <!-- <bean id="AccountDao" class="july.wild.dao.AccountDao"></bean> //不能使用抽象类--> <!-- <bean id="AccountImpl" class="july.wild.ServiceImpl.AccountImpl"></bean>--> <!-- 使用普通工厂的非静态方法方法创建对象--> <!--<bean id="BeanFactory" class="july.wild.factory.BeanFactory"></bean> <bean id="AccountImpl" factory-bean="BeanFactory" factory-method="getServiceImpl"></bean>--> <!-- 使用一个工厂类的静态方法创建对象--> <bean id="AccountImpl" class="july.wild.factory.StaticBeanFactory" factory-method="getAccountImpl" init-method="init" destroy-method="destroy" scope="prototype"></bean> <!-- <bean id="user01" class="july.wild.domain.user"> <constructor-arg name="name" value="guosai"></constructor-arg> <constructor-arg name="age" value="18"></constructor-arg> </bean> --> <bean id="user02" class="july.wild.domain.user"> <property name="name" value="lifei"></property> <property name="date" > <bean factory-bean="simpleDateFormat" factory-method="parse"> <constructor-arg value="1995-01-21"></constructor-arg> </bean> </property> <!--<property name="age" value="10" ></property>--> </bean> <bean id="now" class="java.util.Date"></bean> <bean id="simpleDateFormat" class="java.text.SimpleDateFormat"> <constructor-arg name="pattern" value="yyyy-mm-dd"></constructor-arg> </bean> <bean id="CollectionTest" class="july.wild.domain.CollectionTest"> <property name="array" > <array > <value>10</value> <value>15</value> <value type="int">20</value> </array> </property> <property name="mylist"> <list value-type="java.lang.String"> <value>杨过</value> <value>小龙女</value> </list> </property> <property name="myset"> <set> <value>guojing</value> <value>guojing</value> </set> </property> <property name="myMap"> <map> <entry key="guosai" > <list> <value>guosai</value> <value>lifei</value> </list> </entry> </map> </property> </bean> </beans>