Spring Collections(List,Set,Map,Properties)
来源:互联网 发布:p2p监控软件 编辑:程序博客网 时间:2024/05/07 21:17
下面的例子这是的是spring注入集合(list,set,map,properties)
List---><list/>
Set---><set/>
Map--><map/>
Properties---><pros/>
在CollectionTest中有四种集合属性
com.lzyer.common下
package com.lzyer.common;import java.util.List;import java.util.Map;import java.util.Properties;import java.util.Set;public class CollectionTest {private List<Object> lists;private Set<Object> sets;private Map<Object,Object> maps;private Properties properties;public List<Object> getLists() {return lists;}public void setLists(List<Object> lists) {this.lists = lists;}public Set<Object> getSets() {return sets;}public void setSets(Set<Object> sets) {this.sets = sets;}public Map<Object, Object> getMaps() {return maps;}public void setMaps(Map<Object, Object> maps) {this.maps = maps;}public Properties getProperties() {return properties;}public void setProperties(Properties properties) {this.properties = properties;}@Overridepublic String toString() {return "CollectionTest [lists=" + lists + "\n, sets=" + sets + "\n, maps=" + maps + "\n, properties=" + properties+ "]";}}一个javabean Person.java
package com.lzyer.common;public class Person {private String name;private String address;private int age;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Person [name=" + name + ", address=" + address + ", age=" + age + "]";}}
Spring-Collections.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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><bean id="collection" class="com.lzyer.common.CollectionTest"> <!-- java.util.List --> <property name="lists"> <list> <value>1</value> <ref bean="person"/> <bean class="com.lzyer.common.Person"> <property name="name" value="mair"></property> <property name="address" value="shanghai"></property> <property name="age" value="18"></property> </bean> </list> </property> <!-- java.util.Set --> <property name="sets"> <set> <value>1</value> <ref bean="person"/> <bean class="com.lzyer.common.Person"> <property name="name" value="mair"></property> <property name="address" value="shanghai"></property> <property name="age" value="18"></property> </bean> </set> </property> <!-- java.util.Map --> <property name="maps"> <map> <entry key="key 1" value="1111"/> <entry key="key 2" value-ref="person"/> <entry key="key 3"> <bean class="com.lzyer.common.Person"> <property name="name" value="hello"/> <property name="address" value="world"/> <property name="age" value="30"/> </bean> </entry> </map> </property> <!-- java.util.Properties --> <property name="properties"> <props> <prop key="admin">admin@oraclecsg.com</prop> <prop key="support">support@oraclecsg.com</prop> </props> </property></bean><bean id="person" class="com.lzyer.common.Person"><property name="name" value="lzyer"></property><property name="address" value="hunan"></property><property name="age" value="21"></property></bean></beans>测试类:CollectionApp.java
package com.lzyer.core;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.lzyer.common.CollectionTest;public class CollectionApp {public static void main(String[] args) {@SuppressWarnings("resource")ApplicationContext ac = new ClassPathXmlApplicationContext("Spring-Collection.xml");CollectionTest ct = (CollectionTest)ac.getBean("collection");System.out.println(ct);}}output:
文章参考:http://www.mkyong.com/spring/spring-collections-list-set-map-and-properties-example/
0 0
- Spring Collections(List,Set,Map,Properties)
- Spring(6)-Spring Collections (List, Set, Map, and Properties) example
- Spring Collections (List, Set, Map, and Properties) example
- Spring Properties List Set Map
- spring注入Set,List,Properties和Map
- Spring 注入 List Set Properties Map
- Spring注入Properties、List、Map、Set
- Spring集合 (List,Set,Map,Properties) 实例
- (3) spring注入Properties,List,Set,Map
- List,Set,Map,Properties的Spring注入实例
- List,Set,Map,Properties的Spring注入实例
- List,Set,Map,Properties的Spring注入实例
- Spring中的集合——List、Map、Set、Properties
- Spring注入容器类型List、Map、Properties、Set
- Spring注入集合的值List,Set,Map,Properties
- Spring中注入List Set Map Properties的配置文件
- java collections framework -----List,Set,Map总结
- Java数据结构 List Map Set Collection Collections
- 相机去畸变,以及双目平行校正----极线校正(一)————之单目畸变校正详细过程
- mariadb-2
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- 虚函数 纯虚函数
- 获取某一时间段特定星期几的所有日期(Java实现)
- Spring Collections(List,Set,Map,Properties)
- js_错误处理机制
- linux下通过yum安装svn及配置
- 二分查找
- volatile
- 【委托delegate】界面传值
- spring-boot 加载本地静态资源文件路径配置
- Java Annotation
- 常见的几种移动app开发模式