Spring 中,注入集合类型的数值方式

 

<bean id="javaCollection" class="com.qie_zi.JavaCollection">
        <property name="addressList">
            <list>
                <value>1</value>
                <value>2</value>
                <value>3</value>
                <value>4</value>
            </list>
        </property>
        
        <property name="addressMap">
            <map>
                <entry key="1" value="1"></entry>        
                <entry key="2" value="2"></entry>        
                <entry key="3" value="3"></entry>        
                <entry key="4" value="4"></entry>        
            </map>
        </property>
        
        <property name="addressSet">
            <set>
                <value>1</value>
                <value>2</value>
                <value>3</value>
                <value>4</value>
            </set>
        </property>
        
        <property name="addressProp">
            <props>
                <prop key="1">1</prop>
                <prop key="1">2</prop>
                <prop key="1">3</prop>
                <prop key="1">4</prop>
            </props>
        </property>
    </bean>

 

list  

<property name="addressList">
            <list>
                <value>1</value>
                <value>2</value>
                <value>3</value>
                <value>4</value>
            </list>
        </property>

 

 

map

<property name="addressMap">
            <map>
                <entry key="1" value="1"></entry>        
                <entry key="2" value="2"></entry>        
                <entry key="3" value="3"></entry>        
                <entry key="4" value="4"></entry>        
            </map>
        </property>

 

 

set

<property name="addressSet">
            <set>
                <value>1</value>
                <value>2</value>
                <value>3</value>
                <value>4</value>
            </set>
        </property>

 

 

Properties

<property name="addressProp">
            <props>
                <prop key="1">1</prop>
                <prop key="1">2</prop>
                <prop key="1">3</prop>
                <prop key="1">4</prop>
            </props>
        </property>

 

 

 附录:pojo

 

package com.qie_zi;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class JavaCollection {
    Map addressMap;
    List addressList;
    Set addressSet;
    Properties addressProp;

    public Map getAddressMap() {
        return addressMap;
    }

    public void setAddressMap(Map addressMap) {
        this.addressMap = addressMap;
    }

    public List getAddressList() {
        return addressList;
    }

    public void setAddressList(List addressList) {
        this.addressList = addressList;
    }

    public Set getAddressSet() {
        return addressSet;
    }

    public void setAddressSet(Set addressSet) {
        this.addressSet = addressSet;
    }

    public Properties getAddressProp() {
        return addressProp;
    }

    public void setAddressProp(Properties addressProp) {
        this.addressProp = addressProp;
    }

}