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对象赋值
随机推荐
- SQL RIGHT JOIN 关键字
SQL RIGHT JOIN 关键字 RIGHT JOIN 关键字会右表 (table_name2) 那里返回所有的行,即使在左表 (table_name1) 中没有匹配的行. RIGHT JOIN ...
- JavaScript中定时器
JavaScript提供定时执行代码的功能,叫做定时器(timer),主要由setTimeout()和setInterval()这两个函数来完成.它们向任务队列添加定时任务. setTimeout() ...
- 【转】C,C++中使用可变参数
可变参数即表示参数个数可以变化,可多可少,也表示参数的类型也可以变化,可以是 int,double还可以是char*,类,结构体等等.可变参数是实现printf(),sprintf()等函数的关键之处 ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.2.7
The set of all invertible matrices is a dense open subset of the set of all $n\times n$ matrices. Th ...
- 《深入Java虚拟机学习笔记》- 第4章 网络移动性
Java虚拟机学习笔记(四)网络移动性
- eclipse+xdebug
root@leeyoung-Satellite-M300:/etc/apache2/sites-available# nano 000-default.conf <IfModule dir_mo ...
- 《UNIX环境高级编程 第2版》读书笔记
CH1-2:基础知识.标准化 1 文件和目录 文件名:不能含/(分隔路径)和null(终止路径),255字符. 目录处理:opendir() readdir() closedir() 更改工作目录:c ...
- leetcode@ [300] Longest Increasing Subsequence (记忆化搜索)
https://leetcode.com/problems/longest-increasing-subsequence/ Given an unsorted array of integers, f ...
- Redis+MongoDB 最佳实践 做到读写分离 -摘自网络
方案1. (被否定) 加上Redis,做到MongoDB的读写分离,单一进程从MongoDB及时把任务同步到Redis中. 看起来很完美,但是上线后出现了各种各样的问题,列举一下: 1.Redis队列 ...
- ant -verbose -debug ...
ant -verbose -debug (target) 可以让ant打印出所执行的command任务