1. 程式人生 > >Spring 集合注入

Spring 集合注入

集合的注入都是給<property>新增子標籤,或者裝配建構函式。

             陣列:<array>

             List<list>

             Set<set>

             Map<map> map存放k/v 鍵值對,使用<entry>描述

             Properties<props>  <prop key=""></prop>  【使用最多】            

        普通資料:

<value>

        引用資料:<ref>

<bean id="collDataId" class="com.itheima.f_xml.e_coll.CollData" >

        <property name="arrayData">

             <array>

                 <value>DS</value>

                 <value>DZD</value>

                 <

value>屌絲</value>

                 <value>屌中屌</value>

             </array>

        </property>

<property name="listData">

             <list>

                <ref bean ="testBean" />

                 <value>於嵩楠</value>

                 <

value>曾衛</value>

                 <value>楊煜</value>

                 <value>曾小賢</value>

             </list>

        </property>

        <property name="setData">

             <set>

                 <value>停封</value>

                 <value>薄紙</value>

                 <value>關係</value>

             </set>

        </property>

        <property name="mapData">

             <map>

                 <entry key="jack" value="傑克"></entry>

                 <entry>

                     <key><value>rose</value></key>   //key的值是rose. Valuekey的屬性。用來設定key的值

                     <value>肉絲</value>

                 </entry>

             </map>

        </property>

        <property name="propsData">

             <props>

                 <prop key="高富帥"></prop>

                 <prop key="白富美"></prop>

                 <prop key="男屌絲"></prop>

<prop key="女屌絲"></prop>

<prop key="大齡女屌絲"></prop>

<prop key="超級女屌絲"></prop>

             </props>

        </property>

    </bean>