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对象赋值
随机推荐
- 学习面试题(day01)
1.什么是JVM及其工作原理? JVM是一种用软件模拟出来的计算机,它用于执行Java程序,有一套非常严格的技术规范,是Java跨平台特性的依赖基础.Java虚拟机有自己想象中的硬件,如处理器.堆栈. ...
- 微信公众平台开发—利用OAuth2.0获取微信用户基本信息
在借鉴前两篇获取微信用户基本信息的基础下,本人也总结整理了一些个人笔记:如何通过OAuth2.0获取微信用户信息 1.首先在某微信平台下配置OAuth2.0授权回调页面: 2.通过appid构造url ...
- 文件上传利器JQuery上传插件Uploadify
在做日常项目中,经常在后台需要上传图片等资源文件,之前使用过几次这个组件,感觉非常好用 ,但是每次使用的时候都是需要经过一番查阅,所以还不如记住在这里,以后使用的时候就翻翻. 他的官方网站如下:htt ...
- POJ 1017 Packets
题意:有一些1×1, 2×2, 3×3, 4×4, 5×5, 6×6的货物,每个货物高度为h,把货物打包,每个包裹里可以装6×6×h,问最少几个包裹. 解法:6×6的直接放进去,5×5的空隙可以用1× ...
- Python脚本控制的WebDriver 常用操作 <五> 访问链接
下面将使用webdriver来访问一个web链接 测试用例场景 测试中,经常会点击几个链接来进行操作,所以访问链接是基本的常见操作 Python脚本 from selenium import webd ...
- Linux批量修改指定目录下的文件或文件夹权限
在Puppet下很头大,尤其是文件拷贝,使用file的mode会导致文件或文件夹都一个权限. 暂时使用命令代替: 最近忙着明年的N多计划,待有空后继续研究.
- ArcGIS 10.2与CityEngine2013共存的安装
直接上干货 大前提:由于License Manager的不同版本无法同时安装,因此要想ArcGIS和CityEngine共存其License Manger必须一致. 通过校验安装包中License M ...
- uvalive 4728 Squares
题意:求所有正方形中两点距离最大值的平方值. 思路:旋转卡壳法. 分别用数组和vector存凸包时,旋转卡壳代码有所不同. #include<cstdio> #include<cma ...
- usb 驱动
usb 驱动学习总结: usb 采用分层的拓扑结构,金字塔型,最多是7层.usb 是主从结构,主和主或者从和从之间不能交换数据.理论上一个usb主控制器最多可接127个设备,协议规定每个usb设备具有 ...
- 【转】SQL中Group By的使用
1.概述 2.原始表 3.简单Group By 4.Group By 和 Order By 5.Group By中Select指定的字段限制 6.Group By All 7.Group By与聚合函 ...