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、总结

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

Spring学习(三)几种集合属性的注入方式的更多相关文章

  1. day38 14-Spring的Bean的属性的注入:集合属性的注入

    集合:List.Set.Map. package cn.itcast.spring3.demo6; import java.util.List; import java.util.Map; impor ...

  2. 【Spring学习笔记-MVC-4】SpringMVC返回Json数据-方式2

    <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...

  3. 【Spring学习笔记-MVC-3】SpringMVC返回Json数据-方式1

    <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...

  4. Spring学习(三)--高级装配

    一.Spring profile 在开发软件的时候,有一个很大的挑战就是将应用程序从一个环境迁 移到另外一个环境.开发阶段中,某些环境相关做法可能并不适合迁 移到生产环境中,甚至即便迁移过去也无法正常 ...

  5. Spring学习(三)

    DI (Dependency Injection) 1.依赖注入,组件之间的依赖关系由容器在运行期间决定.Ioc容器注入应用程序某个对象,它所需要的外部资源(包括对象,资源,常量数据). birthd ...

  6. Spring4学习笔记2-配置集合属性

    1 可使用<list> <map> <set>等来配置集合属性 2 List <!-- 配置List属性 --> <bean id="p ...

  7. Spring学习笔记--自动装配Bean属性

    Spring提供了四种类型的自动装配策略: byName – 把与Bean的属性具有相同名字(或者ID)的其他Bean自动装配到Bean的对应属性中. byType – 把与Bean的属性具有相同类型 ...

  8. Spring学习三----------注入方式

    © 版权声明:本文为博主原创文章,转载请注明出处 Spring注入方式 本篇博客只讲最常用的两种注入方式:设值注入和构造器注入.代码为完整代码,复制即可使用. 1.目录结构 2.pom.xml < ...

  9. spring学习三:Spring的Aop、代理

    ref:https://mp.weixin.qq.com/s/J77asUvw8FcnF-6YlX6AAw AOP相关术语:    Joinpoint(连接点):类里面可以被增强的方法,这些方法称为连 ...

随机推荐

  1. [WC2021] 表达式求值

    考虑我们显然可以对每位分开求解,考虑求出最终答案是\(A_i\)的方案数. 那么我们发现我们这样\(dp\)的话,显然不太行! 会有一个\(i\)的复杂度 但是如果我们做大于等于的话,就只用一遍\(d ...

  2. P3571 [POI2014]SUP-Supercomputer

    *X. P3571 [POI2014]SUP-Supercomputer 题意简述:一棵以 \(1\) 为根的树.\(q\) 次询问,每次给出 \(k\),求至少要多少次同时访问不超过 \(k\) 次 ...

  3. 文件/目录对比:diff命令

    命令格式 diff [参数] [文件1或目录1] [文件2或目录2] Linux diff命令用于比较文件的差异. diff以逐行的方式,比较文本文件的异同处. 如果指定要比较目录,diff会比较目录 ...

  4. R语言与医学统计图形-【14】ggplot2几何对象之直方密度图

    ggplot2绘图系统--几何对象之直方图.密度图 1.直方图 参数. geom_histogram(mapping = , data = , stat = 'bin', #统计变换,概率密度为den ...

  5. 59. Divide Two Integers

    Divide Two Integers My Submissions QuestionEditorial Solution Total Accepted: 66073 Total Submission ...

  6. Linux 软件安装位置选择指南

    Linux 软件安装   Linux 下安装软件不像 Windows 下安装这么简单,Windows 下会自动选择合适安装路径,而 Linux 下安装路径大部分完全由自己决定,我可以将软件安装到任意可 ...

  7. 学习java的第七天

    一.今日收获 1.看完全学习手册上java关键字与标识符两节 2.了解了java的关键字与标识符 二.今日难题 1.基本都理解 三.明日目标 1.继续看完全学习手册上的内容 2.加油!

  8. 超好玩:使用 Erda 构建部署应用是什么体验?

    作者|郑成 来源|尔达 Erda 公众号 导读:最近在 Erda 上体验了一下构建并部署一个应用,深感其 DevOps 平台的强大与敏捷,不过为了大家能够快速上手,我尽量简化应用程序,用一个简单的返回 ...

  9. 逻辑学与Prolog学习笔记

    int a = 3 + 5; 很自然.如果Matrix a, b要加呢?没有运算符重载,a + b是不行的,只能add(a, b). int a = add(3, 5)也行.如果函数名可以用+呢?+( ...

  10. acute, adapt

    acute In Euclidean [欧几里得] geometry, an angle is the figure [图形] formed by two rays, called the sides ...