1、前言

众所周知、java中不只有八大简单类型、还有一些集合类型、本文围绕集合类型的注入做一个总结。


2、项目骨架


3、过程

1、创建实体类AllCollectionType

package com.feng.entity;

import java.util.*;

public class AllCollectionType {
private List<String> listElement;
private String[] arrayElement;
private Set<String> setElement;
private Map<String,String> mapElement;
private Properties propsElement; @Override
public String toString() {
return "AllCollectionType{" +
"listElement=" + listElement +
", arrayElement=" + Arrays.toString(arrayElement) +
", setElement=" + setElement +
", mapElement=" + mapElement +
", propsElement=" + propsElement +
'}';
} public List<String> getListElement() {
return listElement;
} public void setListElement(List<String> listElement) {
this.listElement = listElement;
} public String[] getArrayElement() {
return arrayElement;
} public void setArrayElement(String[] arrayElement) {
this.arrayElement = arrayElement;
} public Set<String> getSetElement() {
return setElement;
} public void setSetElement(Set<String> setElement) {
this.setElement = setElement;
} public Map<String, String> getMapElement() {
return mapElement;
} public void setMapElement(Map<String, String> mapElement) {
this.mapElement = mapElement;
} public Properties getPropsElement() {
return propsElement;
} public void setPropsElement(Properties propsElement) {
this.propsElement = propsElement;
}
}

2、配置applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="collectionDemo" class="com.feng.entity.AllCollectionType">
<property name="listElement">
<list>
<value>足球</value>
<value>蓝球</value>
<value>乒乓球</value>
</list>
</property>
<property name="arrayElement">
<array>
<value>足球1</value>
<value>蓝球1</value>
<value>乒乓球1</value>
</array>
</property>
<property name="setElement">
<set>
<value>足球2</value>
<value>蓝球2</value>
<value>乒乓球2</value>
</set>
</property>
<property name="mapElement">
<map>
<entry>
<key>
<value>foot3</value>
</key>
<value>足球3</value>
</entry>
<entry>
<key>
<value>basket3</value>
</key>
<value>蓝球3</value>
</entry>
<entry>
<key>
<value>pp3</value>
</key>
<value>乒乓球3</value>
</entry>
</map>
</property>
<property name="propsElement">
<props>
<prop key="foot4">足球4</prop>
<prop key="basket4">蓝球4</prop>
<prop key="pp4">乒乓球4</prop>
</props>
</property>
</bean>
</beans>

3、编写测试类

package com.feng.test;

import com.feng.entity.AllCollectionType;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { public static void collectionDemo() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
AllCollectionType type = (AllCollectionType)context.getBean("collectionDemo");
System.out.println(type);
}
public static void main(String[] args) {
collectionDemo();
}
}

4、运行结果

4、总结

本文简单讲述了四种集合属性的注入方式、对之前的注入方式进行了一次补充。

最新文章

  1. MVC判断用是否登录了平台
  2. 知乎日报win10版 - 天天读报【开源】
  3. git常用操作
  4. JVM的类加载机制
  5. 关于for循环条件性能问题
  6. lintcode:Search Insert Position 搜索插入位置
  7. ECSHOP - 二次开发指南---购物车篇
  8. 设置VS2015上关闭和打开tab快捷键
  9. BZOJ 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏( floyd )
  10. DOM简要
  11. selenium-webdriver(python) 11
  12. css3文本字体
  13. 爬取字段和图片 spider_getModelInformation
  14. js 依据“;”折行
  15. xilinx_all_version.lic
  16. for循环,列表,元组
  17. .NET 构造DataTable返回多个json值
  18. 跟我一起使用electron搭建一个文件浏览器应用吧(二)
  19. 雷林鹏分享:XML 命名空间
  20. [BZOJ2616]SPOJ PERIODNI 树形dp+组合数+逆元

热门文章

  1. ServerBootstrap的handler()和childHandler()区别
  2. AtCoder Grand Contest 055 题解
  3. Codeforces 1404D - Game of Pairs(构造)
  4. 第42篇-JNI引用的管理(1)
  5. MYSQL5.8----2
  6. 【3】蛋白鉴定软件之Mascot
  7. C4.5决策树-为什么可以选用信息增益来选特征
  8. react native 导航器 Navigator 简单的例子
  9. Beautiful Soup解析库的安装和使用
  10. PDFium 渲染