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注入与遍历的更多相关文章

  1. Spring中注入List,Set,Map,Properties的xml文件配置方法

    下面的例子展示了如何注入 List – <list/> Set – <set/> Map – <map/> Properties – <props/> ...

  2. Spring框架xml配置文件 复杂类型属性注入——数组 list map properties DI dependency injection 依赖注入——属性值的注入依赖于建立的对象(堆空间)

    Person类中的各种属性写法如下: package com.swift.person; import java.util.Arrays; import java.util.List; import ...

  3. Java map 详解 - 用法、遍历、排序、常用API等

    尊重原创: http://www.cnblogs.com/lzq198754/p/5780165.html 概要: java.util 中的集合类包含 Java 中某些最常用的类.最常用的集合类是 L ...

  4. Spring集合 (List,Set,Map,Properties) 实例

    下面例子向您展示Spring如何注入值到集合类型(List, Set, Map, and Properties). 支持4个主要的集合类型: List – <list/> Set – &l ...

  5. Spring练习,使用Properties类型注入方式,注入MySQL数据库连接的基本信息,然后使用JDBC方式连接数据库,模拟执行业务代码后释放资源,最后在控制台输出打印结果。

    相关 知识 >>> 相关 练习 >>> 实现要求: 使用Properties类型注入方式,注入MySQL数据库连接的基本信息,然后使用JDBC方式连接数据库,模拟执 ...

  6. Map集合的几种遍历方式

    Map<String ,String> map=new HashMap<String,String>(); map.put("1","value1 ...

  7. SpringBoot中的application.properties外部注入覆盖

    由想要忽略properties中的某些属性,引发的对SpringBoot中的application.properties外部注入覆盖,以及properties文件使用的思考. SpringBoot 配 ...

  8. spring List,Set,Map,Properties,array的配置文件注入方式

    虽然不多,但是有时候在实现的时候,我们还是希望某些参数或者属性通过集合()的方式注入进来,比如配置表参数列表,addresslist,亦或是三方库等等.因为这种改动不是很多,经常一时想不起来,今天做个 ...

  9. DI,依赖注入,给对象赋值 ,get,set,list,set,map,properties对象赋值

随机推荐

  1. Mysql slave 状态之Seconds_Behind_Master

    在MySQL的主从环境中,我们可以通过在slave上执行show slave status来查看slave的一些状态信息,其中有一个比较重要的参数Seconds_Behind_Master.那么你是否 ...

  2. 自适应的CSS代码片段(常用)

    /* Smartphones (portrait and landscape) ----------- */ @media only screen and (min-device-width : 32 ...

  3. Hibernate4.x之映射关系--单向一对多

    在领域模型中,类与类之间最普遍的关系就是关联关系在UML中,关联是有方向的 以Customer和Order为例:一个用户能发出多个订单,而一个订单只能属于一个客户.从Order到Customer的关联 ...

  4. GIS:揭开你神秘的面纱

    转自:http://www.cnblogs.com/gisangela/archive/2013/02/20/2918884.html#!comments GIS从出现到为人所知,只不过经历了短短的几 ...

  5. NGINX(一)内存结构

    ngx_buf_t和ngx_chain_t是nginx中操作内存的重要手段, 很多的数据都需要通过这个结构进行保存. 其中ngx_buf_t中保存一块可用内存, ngx_chain_t则是将内存块连接 ...

  6. (转载)HTML与XHTML有什么区别

    转自:http://zhidao.baidu.com/link?url=8wvu7Jbzr-wjeKdWCwWkIiJNSpO3HHLERkgQu1QzuLOPT0zvzkHn9HbAFEjPdchP ...

  7. Ofbiz初探

    转:http://xmmartin.blog.51cto.com/2310947/771236 主导建设一个电子商务系统希望从Ofbiz了解中获得一些借鉴1.下载ofbiz,目前的版本是10.04,下 ...

  8. WSGI和PASTE

    WSGI就是一个标准,WSGI server就是实现了这个标准的一个容器.这个标准类似于如下的东东: 1 2 3 4 5 6 7 8 9 10 11 from wsgiref.simple_serve ...

  9. 题解西电OJ (Problem 1003 -最喜欢的数字)--动态规划

    Description zyf最喜欢的数字是1!所以他经常会使用一些手段,把一些非1的数字变 成1,并为此得意不已.他会且仅会的两种手段是: 1.把某个数m除以某个质数p——当然p必须能整除这个数,即 ...

  10. ubuntu openstack spice

    Openstack启用spice协议 #控制节点 #安装 ? 1 apt-get install nova-spiceproxy spice-html5 spice-vdagent #配置 nano ...