Spring、基本类型属性和集合类型属性的注入
来源:互联网 发布:修改linux时间 编辑:程序博客网 时间:2024/04/28 09:02
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>
测试代码:
@Testpublic 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));}}
0 0
- Spring、基本类型属性和集合类型属性的注入
- Spring对集合类型的属性注入
- spring装配基本属性和集合类型
- Spring自动类型转换/集合属性注入
- Spring-注入参数详解-[集合类型属性]
- 八.Spring的属性注入-注入对象,复杂的集合类型属性
- spring如何注入Date类型的属性
- spring如何注入Date类型的属性
- spring对象类型属性的注入
- Spring注入对象类型的属性
- Spring注入复杂类型属性
- spring复杂类型属性注入
- spring注入对象类型属性
- Spring注入复杂类型属性
- Spring (三)注入依赖对象、注入集合类型的属性
- Spring注入Date类型的属性,自定义Date属性编辑器
- 对象类型的属性注入
- 复杂类型的属性注入
- PorterDuff.Mode与Xfermode(android 6.0)
- <iOS>typeof(self)的作用
- JNI 交互备忘
- UISwipeGestureRecognizer 侧滑手势
- 浅析nil、Nil、NULL和NSNull之间的区别与联系
- Spring、基本类型属性和集合类型属性的注入
- 【Codeforces Round 326 (Div 2)D】【DP】Duff in Beach 数列重复取数最多k次使得单调不下降
- apt-get update 和 upgrade 的区别
- swift 快速奔跑的兔几 本节的内容是:SpriteKit第6讲 照明效果
- 使用Gson进行json数据转换(list to json 和json to list)
- UML之对象图
- IOS中UITableViewCell使用详解
- CSS-页面特效
- 欢迎使用CSDN-markdown编辑器