Spring、基本类型属性和集合类型属性的注入
Spring 还可以对基本属性和集合类型属性进行注入:
public interface PersonIService {
public String getBaseProperty();
public Set<String> getSets();
public List<Integer> getList();
public Properties getProperties();
public Map<String, String> getMaps();
}
public class PersonServiceImpl implements PersonIService {
private String baseProperty;
private Set<String> sets;
private List<Integer> list;
private Properties properties;
private Map<String,String> maps; 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<Integer> getList() {
return list;
} public void setList(List<Integer> list) {
this.list = list;
} public Set<String> getSets() {
return sets;
} public String getBaseProperty() {
return baseProperty;
} public void setBaseProperty(String baseProperty) {
this.baseProperty = baseProperty;
} public void setSets(Set<String> sets) {
this.sets = sets;
}
}
beans.xml:
<bean id="personIService" class="cn.server.impl.PersonServiceImpl">
<property name="baseProperty" value="value:基本属性1" />
<property name="sets">
<set>
<value>set装配-value1</value>
<value>set装配-value2</value>
<value>set装配-value3</value>
</set>
</property>
<property name="list">
<list>
<value>11</value>
<value>12</value>
<value>13</value>
</list>
</property>
<property name="properties">
<props>
<prop key="property1">value1</prop>
<prop key="property2">value2</prop>
<prop key="property3">value3</prop>
</props>
</property>
<property name="maps">
<map>
<entry key="map1" value="value1" />
<entry key="map2" value="value2" />
<entry key="map3" value="value3" />
</map>
</property>
</bean>
测试代码:
@Test
public void otherTest(){
ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
PersonIService personIService=(PersonIService)ac.getBean("personIService");
System.out.println("========基本属性注入============");
System.out.println(personIService.getBaseProperty());
System.out.println("========Set集合类型注入============");
for(String str : personIService.getSets()){
System.out.println(str);
}
System.out.println("========list集合类型注入============");
for(Integer i : personIService.getList()){
System.out.println(i);
}
System.out.println("========properties集合类型注入============");
for(Object key : personIService.getProperties().keySet()){
System.out.println(key+"="+personIService.getProperties().getProperty(key.toString()));
}
System.out.println("========map集合类型注入============");
for(Object key : personIService.getMaps().keySet()){
System.out.println(key+"="+personIService.getMaps().get(key));
}
}
Spring、基本类型属性和集合类型属性的注入的更多相关文章
- 【Spring实战】—— 7 复杂集合类型的注入
之前讲解了Spring的基本类型和bean引用的注入,接下来学习一下复杂集合类型的注入,例如:List.Set.Map等. 对于程序员来说,掌握多种语言是基本的技能. 我们这里做了一个小例子,程序员们 ...
- Python中的集合类型分类和集合类型操作符解析
集合类型 数学上,把set称作由不同的元素组成的集合,集合(set)的成员通常被称作集合元素(set elements). Python把这个概念引入到它的集合类型对象里.集合对象是一组无 ...
- 05Spring_Bean属性的集合类型的注入
- Spring.NET学习笔记8——集合类型的注入(基础篇)
1.基础类 public class Happy { public override string ToString() { return &q ...
- Swift中的集合类型
一.引子: 在2014年10月TIOBE编程语言排行榜中,Swift位居第18位,从2014WWDC发布会首次公布至今不到半年时间,swift一直受到编程人 员的追捧,其热衷程度并不亚于当红巨星Tay ...
- The Swift Programming Language-官方教程精译Swift(5)集合类型 -- Collection Types
Swift语言提供经典的数组和字典两种集合类型来存储集合数据.数组用来按顺序存储相同类型的数据.字典虽然无序存储相同类型数据值但是需要由独有的标识符引用和寻址(就是键值对). Swift语言里的数 ...
- Swift 学习- 05 -- 集合类型
// 集合类型 // swift 提供 Arrays , Sets 和 Dictionaries 三种基本的集合类型用来存储数据 , 数组(Arrays) 是有序数据的集, 集合(Sets)是无序无重 ...
- Redis常用命令入门5:有序集合类型
有序集合类型 上节我们一起学习了集合类型,感受到了redis的强大.现在我们接着学Redis的最后一个类型——有序集合类型. 有序集合类型,大家从名字上应该就可以知道,实际上就是在集合类型上加了个有序 ...
- 可迭代的集合类型使用foreach语句
在学习算法这本书图论那一部分的时候,接触到了几个类似for(int w:G.adj(v)),的语句,不是很理解,就去百度,发现这是一种叫做foreach的语法,在书的76页有讲到,但是之前没认真看书, ...
随机推荐
- QT Creator 2.7.2 代码自动补全快捷键设置
在QT Creater界面点[工具]再进[选项]找到[环境]下的[键盘]选项,搜索[CompleteThis]发现默认快捷键就是CTRL+SPACE,把它删除,然后添加自己想设置的快捷键(因为之前用e ...
- C语言的本质(15)——C语言的函数接口入门
C语言的本质(15)--C语言的函数接口 函数的调用者和其实现者之间存在一个协议,在调用函数之前,调用者要为实现者提供某些条件,在函数返回时,实现者完成调用者需要的功能. 函数接口通过函数名,参数和返 ...
- Easyui几种布局方式的使用
1.通过标记创建layout. 记得添加"easyui-layout"样式给div标记. <div id="cc" class="easyui ...
- linux的7种运行级别<学习笔记>
Linux系统有7个运行级别(runlevel) 运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动 运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆 运行级别 ...
- openstack 使用cloud init 和 console-log, nbd或者libguestfs 获取VM中的硬件信息。
以获取PCI的信息为例. 基本代码: pci.py import base64 import guestfs from functools import partial import os impor ...
- MediaInfo使用简介(新版本支持HEVC)
MediaInfo 用来分析视频和音频文件的编码和内容信息,是一款是自由软件 (免费使用.免费获得源代码).他除了提供DLL之外,本身也提供GUI工具用于查看视频信息.我使用中发现,新版本的Media ...
- 关于Makefile.am中与Build相关的变量设置 AM_CPPFLAGS
http://tonybai.com/2010/10/26/about-variables-related-to-building-in-makefile-am/ 关于Makefile.am中与Bui ...
- This function or variable may be unsafe. Consider using scanf_s instead.
去掉安全检查,开头加上即可: #define _CRT_SECURE_NO_WARNINGS 或者: 严重性代码 说明项目文件行禁止显示状态 错误C4996 'scanf': This functio ...
- 聚类算法初探(四)K-means
最近由于工作需要,对聚类算法做了一些相关的调研.现将搜集到的资料和自己对算法的一些理解整理如下,供大家参考. 另外在算法代码方面,我也做了一些实现(包括串行和并行),欢迎感兴趣的朋友探讨和交流. 第一 ...
- 实现简答LinkedList
package com.表栈和队列; import java.util.Iterator; /** * 实现LinkedList * 60页 * @author zj * * @param ...