spring 配置文件中如何注入map list set等类型

原文链接: http://www.cnblogs.com/fdzfd/p/7151989.html

一:原文链接

http://blog.csdn.net/qyf_5445/article/details/9466593

二:配置类

package com.lc.collection;  
  
import java.util.List;  
import java.util.Map;  
import java.util.Properties;  
import java.util.Set;  
  
public class Department {  
  
    private String name;  
    private String [] empName;//数组  
    private List empList;//list集合  
    private Set empsets;//set集合  
    private Map empMaps;//map集合  
    private Properties pp;//Properties的使用  
  
      
    public Set getEmpsets() {  
        return empsets;  
    }  
    public void setEmpsets(Set empsets) {  
        this.empsets = empsets;  
    }  
    public String[] getEmpName() {  
        return empName;  
    }  
    public void setEmpName(String[] empName) {  
        this.empName = empName;  
    }  
    public String getName() {  
        return name;  
    }  
    public void setName(String name) {  
        this.name = name;  
    }  
    public List getEmpList() {  
        return empList;  
    }  
    public void setEmpList(List empList) {  
        this.empList = empList;  
    }  
    public Map getEmpMaps() {  
        return empMaps;  
    }  
    public void setEmpMaps(Map empMaps) {  
        this.empMaps = empMaps;  
    }  
    public Properties getPp() {  
        return pp;  
    }  
    public void setPp(Properties pp) {  
        this.pp = pp;  
    }  
  
}  

三:xml配置

xml version="1.0" encoding="utf-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
        xmlns:context="http://www.springframework.org/schema/context"  
        xmlns:tx="http://www.springframework.org/schema/tx"  
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd  
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
  
<bean id="department" class="com.hsp.collection.Department">  
<property name="name" value="财务部"/>  
  
  
<property name="empName">  
    <list>  
        <value>小明value>  
        <value>小明小明value>  
        <value>小明小明小明小明value>  
    list>  
property>  
  
  
<property name="empList">  
    <list>  
        <ref bean="emp2" />  
        <ref bean="emp1"/>  
        <ref bean="emp1"/>  
        <ref bean="emp1"/>  
        <ref bean="emp1"/>  
        <ref bean="emp1"/>  
        <ref bean="emp1"/>  
    list>  
property>  
  
  
<property name="empsets">  
    <set>  
        <ref bean="emp1" />  
        <ref bean="emp2"/>  
        <ref bean="emp2"/>  
        <ref bean="emp2"/>  
        <ref bean="emp2"/>  
    set>  
property>  
  
  
<property name="empMaps">  
    <map>  
        <entry key="11" value-ref="emp1" />   
        <entry key="22" value-ref="emp2"/>  
        <entry key="22" value-ref="emp1"/>  
    map>  
property>  
  
  
<property name="pp">  
    <props>  
        <prop key="pp1">abcdprop>  
        <prop key="pp2">helloprop>  
    props>  
property>  
bean>  
  
<bean id="emp1" class="com.hsp.collection.Employee">  
    <property name="name" value="北京"/>  
    <property name="id" value="1"/>  
bean>  
<bean id="emp2" class="com.hsp.collection.Employee">  
    <property name="name" value="天津"/>  
    <property name="id" value="2"/>  
bean>  
  
beans>  

 

转载于:https://www.cnblogs.com/fdzfd/p/7151989.html

你可能感兴趣的:(spring 配置文件中如何注入map list set等类型)