spring-向collection注值

beans.xml:





	
	
	
		
			小明
			大明
			大大明
		
	
	
	
		
			
			
		
	
	
	
	
		
			
			
		
	
	
	
	
		
			
			
		
	






	
	


	
	








Department.java:
package com.collection;

import java.util.*;

public class Department {
	private String name;
	private String []empName;
	private List emplist;
	private Set empsets;
	private Map empMaps;
	
	
	public Map getEmpMaps() {
		return empMaps;
	}
	public void setEmpMaps(Map empMaps) {
		this.empMaps = empMaps;
	}
	public Set getEmpsets() {
		return empsets;
	}
	public void setEmpsets(Set empsets) {
		this.empsets = empsets;
	}
	public List getEmplist() {
		return emplist;
	}
	public void setEmplist(List emplist) {
		this.emplist = emplist;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String[] getEmpName() {
		return empName;
	}
	public void setEmpName(String[] empName) {
		this.empName = empName;
	}
}
Employee.java:
package com.collection;

public class Employee {
	private String name;
	private int id;

	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
test.java:
package com.collection;

import java.util.Map.Entry;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class test1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ApplicationContext ac=new ClassPathXmlApplicationContext("com/collection/beans.xml");
		Department a=(Department) ac.getBean("department");
		String []empName=a.getEmpName();
		for(int q=0;q e:a.getEmpMaps().entrySet()	){
			System.out.println(e.getKey()+" "+e.getValue().getName());
		}
	}

}




你可能感兴趣的:(spring)