spring框架(3)— spring集合类的注入
1.Car.java
package com.eniac.beans;
public class Car {
private String type;
private String factory;
private double price;
public Car(){
}
public Car(String type, String factory, double price) {
super();
this.type = type;
this.factory = factory;
this.price = price;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getFactory() {
return factory;
}
public void setFactory(String factory) {
this.factory = factory;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return "Car [type=" + type + ", factory=" + factory + ", price="
+ price + "]";
}
}
2.Person.java
package com.eniac.beans; import java.util.List;
import java.util.Map; public class Person
{
private String name;
private int age;
private List<Car> cars;
private List<String> names;
private Map<String, Car> maps; public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public List<Car> getCars() {
return cars;
}
public void setCars(List<Car> cars) {
this.cars = cars;
}
public List<String> getNames() {
return names;
}
public void setNames(List<String> names) {
this.names = names;
}
public Map<String, Car> getMaps() {
return maps;
}
public void setMaps(Map<String, Car> maps) {
this.maps = maps;
}
@Override
public String toString() {
return "Person [name=" + name + ", age=" + age + ", cars=" + cars
+ ", names=" + names + ", maps=" + maps + "]";
}
}
3.bean.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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
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-4.0.xsd"> <bean id="person1" class="com.eniac.beans.Person">
<property name="name" value="科比"/>
<property name="age" value="24"/>
<property name="cars">
<list>
<bean id="car1" class="com.eniac.beans.Car" p:type="BMW" p:factory="长安" p:price="4000"></bean>
<bean id="car2" class="com.eniac.beans.Car">
<property name="type" value="Benz"></property>
<property name="factory" value="一汽"></property>
<property name="price" value="300000"></property>
</bean>
</list>
</property> <property name="names">
<list>
<value>aaa</value>
<value>bbb</value>
</list>
</property>
<property name="maps">
<map>
<entry key="car1" value-ref="car1"/>
<entry key="car2" value-ref="car2"/>
</map>
</property>
</bean>
</beans>
1.使用了p命名空间;
2.通过使用<list>子标签,将list的值注入;
3.使用<map>子标签,将map的值注入。
spring框架(3)— spring集合类的注入的更多相关文章
- spring框架--IOC容器,依赖注入
思考: 1. 对象创建创建能否写死? 2. 对象创建细节 对象数量 action 多个 [维护成员变量] service 一个 [不需要维护公共变量] dao 一个 [不需要维护 ...
- spring框架(1)— 依赖注入
依赖注入 spring核心容器就是一个超级大工厂,所以的对象(数据源.hibernate SessionFactory等基础性资源)都会被当做spring核心容器的管理对象——spring把容器中的一 ...
- spring框架aop用注解形式注入Aspect切面无效的问题解决
由于到最后我的项目还是有个邪门的错没解决,所以先把文章大概内容告知: 1.spring框架aop注解扫描默认是关闭的,得手动开启. 2.关于Con't call commit when autocom ...
- 《经久不衰的Spring框架:Spring+SpringMVC+MyBatis 整合》
前言 主角即Spring.SpringMVC.MyBatis,即所谓的SSM框架,大家应该也都有所了解,概念性的东西就不写了,有万能的百度.之前没有记录SSM整合的过程,这次刚刚好基于自己的一个小项目 ...
- Spring框架(1)---Spring入门
Spring入门 为了能更好的理解先讲一些有的没的的东西: 什么是Spring Spring是分层的JavaSE/EE full-stack(一站式) 轻量级开源框架 分层 SUN提供的EE的三层结构 ...
- Spring框架学习——Spring的体系结构详解
1.Spring简介 Spring是一个轻量级Java开发框架,最早有Rod Johnson创建,目的是为了解决企业级应用开发的业务逻辑层和其他各层的耦合问题.它是一个分层的JavaSE/JavaEE ...
- 【spring框架】spring获取webapplicationcontext,applicationcontext几种方法详解--(转)
方法一:在初始化时保存ApplicationContext对象代码:ApplicationContext ac = new FileSystemXmlApplicationContext(" ...
- 什么是spring框架?spring特点与好处,使用spring框架的好处是什么?
转载:https://blog.csdn.net/hht006158/article/details/80181207. Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Ja ...
- Spring 框架介绍 [Spring 优点][Spring 应用领域][体系结构][目录结构][基础 jar 包]
您的"关注"和"点赞",是信任,是认可,是支持,是动力...... 如意见相佐,可留言. 本人必将竭尽全力试图做到准确和全面,终其一生进行修改补充更新. 目录 ...
- 一句话概括下spring框架及spring cloud框架主要组件
作为java的屌丝,基本上跟上spring屌丝的步伐,也就跟上了主流技术.spring 顶级项目:Spring IO platform:用于系统部署,是可集成的,构建现代化应用的版本平台,具体来说当你 ...
随机推荐
- [修正] Firemonkey SpeedButton 鼠标移开按钮后 IsPressed 为 False 的问题
未修正: 修正代码: 请将 FMX.StdCtrls.pas 复制到自己的工程目录下,再修改如下代码: procedure TCustomButton.RestoreButtonState; begi ...
- aiohttp爬虫的模板,类的形式
import asyncio import aiohttp import async_timeout from lxml import html from timeit import default_ ...
- Golang Gin 项目包依赖管理 godep 使用
Golang Gin 项目包依赖管理 godep 使用 标签(空格分隔): Go 在按照github.com/tools/godep文档go get完包以后,调整项目结构为$GOPATH/src/$P ...
- SQLSERVER字符串处理函数
sqlserver提供了一系列字符串处理函数:substring.left.right.len.charindex.patindex.replace.replicate.stuff.upper.low ...
- 20155210 2016-2017-2 《Java程序设计》第10周学习总结
20155210 2016-2017-2 <Java程序设计>第10周学习总结 教材学习内容总结 计算机网络概述 网络编程的实质就是两个(或多个)设备(例如计算机)之间的数据传输.按照计算 ...
- 实验三 敏捷开发与XP实践-1
实验内容 XP基础 XP核心实践 相关工具 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim编辑器> 课程 2.完成实验.撰写实验报告,实 ...
- 20155224 2016-2017-2 《Java程序设计》第4周学习总结
20155224 2016-2017-2 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 第六章主要学习了子类与父类的继承. 先定义一个程序,另一程序可继承他 如: publ ...
- 20155233 2016-2017-2 《Java程序设计》第10周学习总结
20155233 2016-2017-2 <Java程序设计>第10周学习总结 学习目标 了解计算机网络基础 掌握Java Socket编程 理解混合密码系统 掌握Java 密码技术相关A ...
- 2017-2018-1 20155308《信息安全技术》实验二——Windows口令破解
2017-2018-1 20155308<信息安全技术>实验二--Windows口令破解 实验原理 口令破解主要有两种方法:字典破解和暴力破解. 字典破解是指通过破解者对管理员的了解,猜测 ...
- Storyboarding by Scripting
Storyboarding by Scripting In the .osu file, under [Events]:Note: underscores can be replaced with s ...