Ioc操作Bean管理(xml注入集合属性)

  1. 注入数组类型属性
  2. 注入List集合类型属性
  3. 注入Map集合类型属性

Stu类

public class Stu {
//1. 数组类型属性
private String[] courses; //2. List集合类型属性
private List<String> list; //3. Map集合类型属性
private Map<String,String> maps; //3. Set集合类型属性
private Set<String> sets; public void setCourses(String[] courses) {
this.courses = courses;
} public void setList(List<String> list) {
this.list = list;
} public void setMaps(Map<String, String> maps) {
this.maps = maps;
} public void setSets(Set<String> sets) {
this.sets = sets;
}
}

xml

    <!--集合类型属性注入-->
<bean id="stu" class="Spring.Ioc.Day04.collection.Stu">
<!--数组-->
<property name="courses" >
<array>
<value>java</value>
<value>c++</value>
</array>
</property>
<!--list-->
<property name="list">
<list>
<value>1</value>
<value>2</value>
</list>
</property>
<!--Map-->
<property name="maps">
<map>
<entry key="1" value="one"></entry>
<entry key="2" value="two"></entry>
</map>
</property>
<!--Set-->
<property name="sets">
<set>
<value>mysql</value>
<value>oracle</value>
</set>
</property>
</bean>
</beans>
  1. 在集合里面设置对象类型值

xml

    <bean>
<!--注入list集合类型,值是对象-->
<property name="courseList">
<list>
<ref bean="course1"></ref>
<ref bean="course2"></ref>
</list>
</property>
</bean> <!--创建多个course对象-->
<bean id="course1" class="Spring.Ioc.Day04.collection.Course">
<property name="cname" value="Spring"></property>
</bean>
<bean id="course2" class="Spring.Ioc.Day04.collection.Course">
<property name="cname" value="MVC"></property>
</bean>
  1. 把集合注入部分提取出来
  • 在spring配置文件中引入名称空间util
  • 使用util标签完成list集合注入提取

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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <!--1 提取list集合类型属性注入-->
<util:list id="bookList">
<value>book1</value>
<value>book2</value>
<value>book3</value>
</util:list>
<!--2 提取list集合类型属性注入使用-->
<bean id="book" class="Spring.Ioc.Day05.collection.book">
<property name="list" ref="bookList"></property>
</bean>
</beans>

book类

public class book {

    private List<String> list;

    public void setList(List<String> list) {
this.list = list;
}
public void test(){
System.out.println(list);
}
}

Spring学习日记03_IOC_属性注入_集合类型属性的更多相关文章

  1. Spring学习日记02_IOC_属性注入_其他类型属性

    ICO操作Bean管理(xml注入其它类型属性) 字面量 null值 <property name="address"> <null></null&g ...

  2. IoC容器-Bean管理XML方式(注入集合类型属性)

    Ico操作Bean管理(xml注入集合属性) 1,注入数组类型属性 2,注入List集合类型属性 3,注入Map集合类型属性 (1)创建类,定义数组.list.map.set类型属性,生成对应set方 ...

  3. Spring、基本类型属性和集合类型属性的注入

    Spring 还可以对基本属性和集合类型属性进行注入: public interface PersonIService { public String getBaseProperty(); publi ...

  4. Spring 属性注入(四)属性键值对 - PropertyValue

    Spring 属性注入(四)属性键值对 - PropertyValue Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) P ...

  5. spring 学习之 bean 的注入方式 property和constructor-arg的使用方式

    spring 学习之 bean 的注入方式 property和constructor-arg的使用方式. bean的注入方式: property 注入是: 通过setxx方法注入. construct ...

  6. Spring学习(三)几种集合属性的注入方式

    1.前言 众所周知.java中不只有八大简单类型.还有一些集合类型.本文围绕集合类型的注入做一个总结. 2.项目骨架 3.过程 1.创建实体类AllCollectionType package com ...

  7. Spring中集合类型属性注入

    我们都知道如何去注入普通属性的值,非常简单,那么我们如何去注入开发中常见的集合类型的属性了,别急,往下看. 这里将介绍如何给Map list set Array Properties 这些属性注入值. ...

  8. Spring 学习笔记 4. 尚硅谷_佟刚_Spring_属性配置细节

    1,字面值 •字面值:可用字符串表示的值,可以通过 <value> 元素标签或 value 属性进行注入. •基本数据类型及其封装类.String 等类型都可以采取字面值注入的方式 •若字 ...

  9. Spring学习日记01_IOC_xml的三种注入方式

    什么是IOC 控制反转,把对象创建和对象之间的调用过程,交给Spring进行管理 使用IOC目的:为了耦合度降低 做入门案例就是IOC实现 IOC底层原理 xml解析 工厂模式 反射 原始方式 cla ...

随机推荐

  1. [bug]MySQL [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause

    参考 http://www.10qianwan.com/articledetail/220315.html

  2. commit信息修改

    场景:向社区提交commit信息,code reviewer给你回复说,请添加TrivialFix并且完善commit信息.好吧,虽然这对代码的运行无关紧要,但是对于日后的代码管理是很有必要的. 解决 ...

  3. Ansible_主机变量和主机组变量的演示

    一.主机变量和主机组变量的演示 1.主机变量和主机组变量的基本语法和规则 请访问:https://www.cnblogs.com/itwangqiang/p/13592362.html 2.首先在/e ...

  4. 855 gpu强 730 3倍

    骁龙730G的GPU规模只有骁龙835的GPU规模的一半,Adreno 618是128 ALUs,而Adreno 540是256 ALUs. 根据GFXBench的数据,对GPU负载比较大的曼哈顿3. ...

  5. 拉勾、Boss直聘、内推、100offer

    BOSS直聘 拉勾.Boss直聘.内推.100offer  

  6. linux python3安装whl包时报错解决:is not a supported wheel on this platform

    原因1 你下载安装的包不是当前平台所支持的 原因2 你下载的包,不符合你所在的平台的安装whl的名称规范,所以出错.比如当前我要安装的包是:pymssql-2.1.5-cp36-cp36m-manyl ...

  7. IDEA中配置maven 全解析教程(Day_08)

    每一个你讨厌的现在,都有一个不够努力的曾经. 一.选择一个maven的版本下载 本文中 maven 下载链接:(apache-maven-3.5.2.rar) https://files-cdn.cn ...

  8. systemverilog数组类型

  9. 记一次zabbix-server故障恢复导致的事故 zabbix-server.log -- One child process died

    前言 zabbix-server昨天出了个问题,不停的重启.昨天摆弄到晚上也不搞清楚原因,按照网上说的各种操作,各种CacheSize.TimeOut.StartPollers都改了,还有什么Incl ...

  10. Spring Mvc Long类型精度丢失

    背景 在使用Spring Boot Mvc的项目中,使用Long类型作为id的类型,但是当前端使用Number类型接收Long类型数据时,由于前端精度问题,会导致Long类型数据转换为Number类型 ...