java_spring_List,Map,Properties,Set注入与遍历
package com.dao.bean.www; import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set; public interface PersonServiceDao { public Map<String, String> getMaps(); public Properties getProperties(); public List<String> getLists(); public Set<String> getSets(); public abstract void save(); }
package com.bean.www; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set; import com.PersonDaoBean.test.PersonDao;
import com.dao.bean.www.PersonServiceDao; public class PersonServiceBean implements PersonServiceDao { private Set<String> sets = new HashSet<String>();
private List<String> lists = new ArrayList<String>();
private Properties properties = new Properties();
private Map<String, String> maps = new HashMap<String, String>(); public Map<String, String> getMaps() {
return maps;
} public void setMaps(Map<String, String> maps) {
this.maps = maps;
} public Properties getProperties() {
return properties;
} public void setProperties(Properties properties) {
this.properties = properties;
} public List<String> getLists() {
return lists;
} public void setLists(List<String> lists) {
this.lists = lists;
} public Set<String> getSets() {
return sets;
} public void setSets(Set<String> sets) {
this.sets = sets;
} public void save() { } }
//注入配置
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="personService" class="com.bean.www.PersonServiceBean"> <property name="sets">
<set>
<value>Set-aaaaaaa</value>
<value>Set-cccccccc</value>
<value>Set-bbbb</value>
<value>Set-bbbb</value>
</set>
</property> <property name="lists">
<list>
<value>List-aaaaaaa</value>
<value>List-cccccccc</value>
<value>List-bbbb</value>
<value>List-bbbb</value>
</list>
</property> <property name="properties">
<props>
<prop key="key1">propties1</prop>
<prop key="key2">propties2</prop>
<prop key="key3">propties3</prop>
</props>
</property> <property name="maps">
<map>
<entry key="mapsKey1" value="aaaaa-mapsValue1"></entry>
<entry key="mapsKey2" value="cccccccc-mapsValue2"></entry>
<entry key="mapsKey3" value="bbbbbbb-mapsValue3"></entry>
</map>
</property> </bean> </beans>
package com.itcast.www; import static org.junit.Assert.*; import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.dao.bean.www.PersonServiceDao; public class TestCaseDemo { @BeforeClass
public static void setUpBeforeClass() throws Exception {
} @Test
public void instanceSpring() { ApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext.xml"); PersonServiceDao personService = (PersonServiceDao) ctx
.getBean("personService"); for (String value : personService.getSets()) {
System.out.println(value);
} System.out.println("*********************************"); for (String value : personService.getLists()) {
System.out.println(value);
} System.out.println("*********************************"); for (Object key : personService.getProperties().keySet()) {
System.out.println(key + " = "
+ personService.getProperties().getProperty((String) key));
} System.out.println("*********************************"); for (String key : personService.getMaps().keySet()) {
System.out.println(key + " = " + personService.getMaps().get(key));
}
} }
java_spring_List,Map,Properties,Set注入与遍历的更多相关文章
- Spring中注入List,Set,Map,Properties的xml文件配置方法
下面的例子展示了如何注入 List – <list/> Set – <set/> Map – <map/> Properties – <props/> ...
- Spring框架xml配置文件 复杂类型属性注入——数组 list map properties DI dependency injection 依赖注入——属性值的注入依赖于建立的对象(堆空间)
Person类中的各种属性写法如下: package com.swift.person; import java.util.Arrays; import java.util.List; import ...
- Java map 详解 - 用法、遍历、排序、常用API等
尊重原创: http://www.cnblogs.com/lzq198754/p/5780165.html 概要: java.util 中的集合类包含 Java 中某些最常用的类.最常用的集合类是 L ...
- Spring集合 (List,Set,Map,Properties) 实例
下面例子向您展示Spring如何注入值到集合类型(List, Set, Map, and Properties). 支持4个主要的集合类型: List – <list/> Set – &l ...
- Spring练习,使用Properties类型注入方式,注入MySQL数据库连接的基本信息,然后使用JDBC方式连接数据库,模拟执行业务代码后释放资源,最后在控制台输出打印结果。
相关 知识 >>> 相关 练习 >>> 实现要求: 使用Properties类型注入方式,注入MySQL数据库连接的基本信息,然后使用JDBC方式连接数据库,模拟执 ...
- Map集合的几种遍历方式
Map<String ,String> map=new HashMap<String,String>(); map.put("1","value1 ...
- SpringBoot中的application.properties外部注入覆盖
由想要忽略properties中的某些属性,引发的对SpringBoot中的application.properties外部注入覆盖,以及properties文件使用的思考. SpringBoot 配 ...
- spring List,Set,Map,Properties,array的配置文件注入方式
虽然不多,但是有时候在实现的时候,我们还是希望某些参数或者属性通过集合()的方式注入进来,比如配置表参数列表,addresslist,亦或是三方库等等.因为这种改动不是很多,经常一时想不起来,今天做个 ...
- DI,依赖注入,给对象赋值 ,get,set,list,set,map,properties对象赋值
随机推荐
- Java [Leetcode 217]Contains Duplicate
题目描述: Given an array of integers, find if the array contains any duplicates. Your function should re ...
- Java [leetcode 21]Merge Two Sorted Lists
题目描述: Merge two sorted linked lists and return it as a new list. The new list should be made by spli ...
- 扩展类加载器-------改变JAVA的父优先类加载顺序
java的类加载机制默认情况下是采用委托模型:当加载某个类时JVM会首先尝试用当前类加载器的父类加载器加载该类,若父类加载器加载不到再由当前类加载器来加载,因此这种模型又叫做“父优先”模型. 但是在实 ...
- Breaking parallel loops in .NET C# using the Stop method z
List<, , , , , , , , , }; Parallel.ForEach(integers, (int item, ParallelLoopState state) => { ...
- 发送复杂的HTTP GET请求并且取回响应。
设计思想: 创建一个HttpWebRequest类的实例,并通过GetReponse()方法取回响应的HTTP响应. 实例方案: string url="http://www.baidu.c ...
- 统计计算与R语言的资料汇总(截止2016年12月)
本文在Creative Commons许可证下发布. 在fedora Linux上断断续续使用R语言过了9年后,发现R语言在国内用的人逐渐多了起来.由于工作原因,直到今年暑假一个赴京工作的机会与一位统 ...
- 【转】ExcelHelper类,用npoi读取Excel文档
//------------------------------------------------------------------------------------- // All Right ...
- 获取EntityFrameWork返回的错误和ModelState中的错误
都是通过循环才能找到具体的错误信息 具体方法参见这两篇文章: EntityFrameWork: http://www.cnblogs.com/shouzheng/archive/2012/04/19/ ...
- ASP.NET_验证控件(class0620)
为什么使用验证控件 当需要让用户输入数据时,用户有可能输入不符合我们程序逻辑要求的信息,所以我们要对输入进行验证. 客户端验证(用户体验,减少服务器端压力) 服务器端验证(防止恶意攻击,客户端js很容 ...
- Java 的集合框架
Java集合框架被设计成要满足以下几个目标. 该框架必须是高性能的.基本集合(动态数组,链表,树,哈希表)的实现也必须是高效的. 该框架允许不同类型的集合,以类似的方式工作,具有高度的互操作性. 对一 ...