1. 程式人生 > >Spring中IOC容器對數組,集合的相關bean的裝配

Spring中IOC容器對數組,集合的相關bean的裝配

art prop emp pri val 對數 try ioc容器 blog

<bean id="department" class="com.pojo.Department">
     
      <property name="name" value="人事部"></property>
          <!-- 數組 -->
      <property name="empName">
        <list>
          <value>張三</value>
          <value>李四</value>
        </list>
      </property>
      <!-- list -->
      <property name="list">
        <list>
         <ref bean="employee"/>
         <ref bean="employee2"/>
        </list>
      </property>
            <!-- set -->
      <property name="set">
       <set>
         <ref bean="employee"/>
         <ref bean="employee2"/>
       </set>
      </property>      
      <!-- map -->
      <property name="map">
        <map>
          <entry key="1" value-ref="employee"></entry>
          <entry key="2" value-ref="employee2"></entry>
        </map>
      </property>
    </bean>
   
   
    <bean id="employee" class
="com.pojo.employee"> <property name="name" value="張三" /> <property name="id" value="1"/> </bean> <bean id="employee2" class="com.pojo.employee"> <property name="name" value="李四"/> <property name="id" value="2"/> </bean>

Spring中IOC容器對數組,集合的相關bean的裝配