注入集合类型数据

2020-02-19 16:03:47来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

注入集合类型数据

Person:

package com.ly.spring;
import java.util.*;
public class Person {
    private String[] strArr;
    private List<String> strList;
    private Map<String,String> strMap;
    private Set<String> strSet;
    private Properties prop;
    public void setStrArr(String[] strArr) {
        this.strArr = strArr;
    }
    public void setStrList(List<String> strList) {
        this.strList = strList;
    }
    public void setStrMap(Map<String, String> strMap) {
        this.strMap = strMap;
    }
    public void setStrSet(Set<String> strSet) {
        this.strSet = strSet;
    }
    public void setProp(Properties prop) {
        this.prop = prop;
    }
    public String[] getStrArr() {
        return strArr;
    }
    public List<String> getStrList() {
        return strList;
    }
    public Map<String, String> getStrMap() {
        return strMap;
    }
    public Set<String> getStrSet() {
        return strSet;
    }
    public Properties getProp() {
        return prop;
    }
}

配置文件:

<?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="person" class="com.ly.spring.Person">
        <property name="strArr">
            <array>
                <value>AAA</value>
                <value>BBB</value>
                <value>CCC</value>
            </array>
        </property>
        <property name="strList">
            <list>
                <value>DDD</value>
                <value>EEE</value>
                <value>FFF</value>
            </list>
        </property>
        <property name="strSet">
            <set>
                <value>GGG</value>
                <value>HHH</value>
                <value>III</value>
            </set>
        </property>
        <property name="strMap">
            <map>
                <entry key="k1" value="JJJ"></entry>
                <entry key="k2" value="KKK"></entry>
                <entry key="k3" value="LLL"></entry>
            </map>
        </property>
        <property name="prop">
            <props>
                <prop key="p1">MMM</prop>
                <prop key="p2">NNN</prop>
                <prop key="p3">OOO</prop>
            </props>
        </property>
    </bean>
</beans>

 


原文链接:https://www.cnblogs.com/liuyang-520/p/12332443.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Docker学习笔记(2):使用Dockerfile构建镜像

下一篇:Dubbo-服务注册中心之AbstractRegistry