Spring中数组、List、Set数据的注入
来源:互联网 发布:购买的淘宝店铺安全吗 编辑:程序博客网 时间:2024/05/29 13:24
<?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="person" class="com.amaker.spring.Person"> <!--数组的注入 --> <property name="names"> <list> <value>aa</value> <value>bb</value> <value>cc</value> <value>dd</value> </list> </property> <!--list的注入 --> <property name="studentList"> <list> <ref bean="student"/> <ref bean="student1"/> </list> </property> <!--Set的注入 --> <property name="studentSet"> <set> <ref bean="student"/> <ref bean="student1"/> <ref bean="student1"/> <ref bean="student1"/> <ref bean="student1"/> </set> </property> <!--Map的注入 --> <property name="studentMap"> <map> <entry key="11" value-ref="student"></entry> <entry key="22" value-ref="student1"></entry> </map> </property> <!--Properties的注入 --> <property name="pp"> <props> <prop key="key1">aaaaaaaaaaaaaaaaaaa</prop> <prop key="key2">bbbbbbbbbbbbbbbbbbb</prop> </props> </property> </bean> <bean id="student" class="com.amaker.spring.Student"> <property name="name"> <value>小明</value> </property> </bean> <bean id="student1" class="com.amaker.spring.Student"> <property name="name"> <value>大明</value> </property> </bean> </beans><pre name="code" class="java">package com.amaker.spring;public class Student {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}}
package com.amaker.spring;import java.util.List;import java.util.Map;import java.util.Properties;import java.util.Set;public class Person {private String []names;private List<Student> studentList;private Set<Student> studentSet;private Map<String,Student> studentMap;private Properties pp;public Properties getPp() {return pp;}public void setPp(Properties pp) {this.pp = pp;}public Map<String, Student> getStudentMap() {return studentMap;}public void setStudentMap(Map<String, Student> studentMap) {this.studentMap = studentMap;}public Set<Student> getStudentSet() {return studentSet;}public void setStudentSet(Set<Student> studentSet) {this.studentSet = studentSet;}public List<Student> getStudentList() {return studentList;}public void setStudentList(List<Student> studentList) {this.studentList = studentList;}public String[] getNames() {return names;}public void setNames(String[] names) {this.names = names;}}
package com.amaker.spring;import java.util.Enumeration;import java.util.Iterator;import java.util.Map;import java.util.Properties;import java.util.Map.Entry;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test {/** * @param args */public static void main(String[] args) {ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");Person person = (Person)ac.getBean("person");//获取注入的数组for(String name:person.getNames()){System.out.println(name);}//获取注入的集合Listfor(Student student:person.getStudentList()){System.out.println(student.getName());}//获取注入的集合Setfor(Student student:person.getStudentSet()){System.out.println(student.getName());}//获取注入的Map数据,两种获取方式//1,迭代获取方式:Map<String,Student> studentMap = person.getStudentMap();Iterator it = studentMap.keySet().iterator();while(it.hasNext()){String key = (String) it.next();Student s = studentMap.get(key);System.out.println("key= " +key + " "+s.getName());}//2,entryfor(Entry<String, Student> entry:person.getStudentMap().entrySet()){System.out.println(entry.getKey()+" "+entry.getValue().getName());}//获取注入的属性数据//第一种获取方式Properties pp = person.getPp();for(Entry<Object, Object> entry:pp.entrySet()){System.out.println(entry.getKey() + " "+entry.getValue());}//第二种获取方式Enumeration en = pp.keys();while(en.hasMoreElements()){String key = (String) en.nextElement();System.out.println(key + " "+pp.getProperty(key));}}}
0 0
- Spring中数组、List、Set数据的注入
- Spring中数组,List,Map,Set注入方式
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中List、Set、Map、数组注入方式中标签的使用
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中注入List Set Map Properties的配置文件
- set,list,Map,数组的注入
- spring注入list set map
- Spring中List Set Map 和Date注入
- spring 配置文件中如何注入map list set等类型
- spring的list,set,map的依赖注入
- List,Set,Map,Properties的Spring注入实例
- List,Set,Map,Properties的Spring注入实例
- 使用第三方库的apk 在Ubuntu下编译后不能正常运行
- 配置DNS服务器
- 错误1error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.
- Ubuntu桌面环境打开Eclipse初见JRE错误
- iOS中常用功能的整理与备注
- Spring中数组、List、Set数据的注入
- Borland C++ Builder 6.0 XML处理总结
- javascript:void (0)的含义
- Error: java.lang.UnsupportedOperationException: Not implemented by the HftpFileSystem FileSystem imp
- GPS数据读取与处理(一)
- namesrv
- nyoj 288 士兵杀敌(五)
- "mkimage" command not found - U-Boot images will not be built
- 验证信息小知识