spring注入list set map
来源:互联网 发布:淘宝推广流程 编辑:程序博客网 时间:2024/05/22 13:46
java实体类
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<Employee> empList;//list集合 private Set<Employee> empsets;//set集合 private Map<String,Employee> empMaps;//map集合 private Properties pp;//Properties的使用 public Set<Employee> getEmpsets() { return empsets; } public void setEmpsets(Set<Employee> 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<Employee> getEmpList() { return empList; } public void setEmpList(List<Employee> empList) { this.empList = empList; } public Map<String, Employee> getEmpMaps() { return empMaps; } public void setEmpMaps(Map<String, Employee> empMaps) { this.empMaps = empMaps; } public Properties getPp() { return pp; } public void setPp(Properties pp) { this.pp = pp; } }
spring配置文件
<?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> <!-- 给list注入值 list 中可以有相当的对象 --> <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> <!-- 给set注入值 set不能有相同的对象 --> <property name="empsets"> <set> <ref bean="emp1" /> <ref bean="emp2"/> <ref bean="emp2"/> <ref bean="emp2"/> <ref bean="emp2"/> </set> </property> <!-- 给map注入值 map只有key不一样,就可以装配value --> <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">abcd</prop> <prop key="pp2">hello</prop> </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>
调用
String[] configs = {"applicationContext.xml"};ApplicationContext ac =new ClassPathXmlApplicationContext(configs);MessageBean msgBean = (MessageBean)ac.getBean("messagebean");msgBean.show();
阅读全文
0 0
- spring注入list set map
- spring注入Set,List,Properties和Map
- spring 注入map,set,list,property
- Spring 注入 List Set Properties Map
- spring如何注入List,Set,Map对象
- Spring注入Properties、List、Map、Set
- (3) spring注入Properties,List,Set,Map
- List,Set,Map,Properties的Spring注入实例
- List,Set,Map,Properties的Spring注入实例
- List,Set,Map,Properties的Spring注入实例
- Spring 普通属性注入(int ,String, List, Map, Set, String[])
- Spring中数组,List,Map,Set注入方式
- spring的list,set,map的依赖注入
- Spring注入容器类型List、Map、Properties、Set
- Spring注入集合的值List,Set,Map,Properties
- Spring中List Set Map 和Date注入
- Spring中注入List Set Map Properties的配置文件
- spring 配置文件中如何注入map list set等类型
- hdu 1045 Fire Net
- Tensorflow累加的实现
- Oracle 通过ODBC 连接GreenPlum
- Java中常用缓存Cache机制的实现
- 十进制与八进制和十六进制之间的转换
- spring注入list set map
- 漫谈jvm垃圾收集(2)
- Linux Rootkit 系列
- echarts地图使用问题,下钻
- Android序列化:Serializable Parcelable
- C#190课的主要内容
- AI-图书馆(一)
- mybatis穿对象和参数 的处理
- Oracle_SQL之lag()和lead()函数使用