spring 基础回顾 tips02

spring注入list 、set、 map、 properties

1.list

在xml中这样写:

		<property name="list">
			<list>
				<value>Michael Huang</value>
				<ref bean="student"></ref>
				<value>110</value>
			</list>
		</property>

Java类中同样需要属性的setter和getter:

private List list;

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

遍历一下,测试:

for (Object obj : list) {
			System.out.println("看看你注入的这些是啥:" + obj);
		}

console中打印注入的对象:

看看你注入的这些是啥:Michael Huang
看看你注入的这些是啥:<a target=_blank href="mailto:[email protected]">[email protected]</a>
看看你注入的这些是啥:110

ps:可以注入不同类型的对象,所以没有规定泛型接口,一切皆对象,什么都可以放。

2.set

<property name="set">
	<set>
		<value  type="java.lang.String">Michael Jordon</value>
		<ref bean="student"></ref>
	</set>
</property>

3.map

<property name="map">
	<map>
		<entry key="abc" value="1231"></entry>
		<entry key-ref="student" value-ref="student"></entry>
	</map>
</property>

遍历map

Collection c = map.values();
Iterator it = c.iterator();
	for (; it.hasNext();) {
	System.out.println("from map---------" + it.next());
	}

4properties

<property name="props">
	<props>
        	<prop key="michael">[email protected]</prop>
                <prop key="tom">[email protected]</prop>
        </props>
</property>
Collection c1 = props.values();
		Iterator it1 = c1.iterator();
		for (; it1.hasNext();) {
			System.out.println("from props---------" + it1.next());
		}

spring 基础回顾 tips02

时间: 2024-08-08 10:07:18

spring 基础回顾 tips02的相关文章

spring 基础回顾 tips01

spring 属性注入时,类中必须有setter 和 getter方法. spring配置文件中: java业务类中注入DAO: private StudentDao studentDao; // 通过属性注入 public StudentDao getStudentDao() { return studentDao; } public void setStudentDao(StudentDao studentDao) { this.studentDao = studentDao; } spri

spring基础回顾

1.什么是Spring框架?Spring框架有哪些主要模块? Spring框架是一个为Java应用程序的开发提供了综合.广泛的基础性支持的Java平台.Spring帮助开发者解决了开发中基础性的问题,使得开发人员可以专注于应用程序的开发.Spring框架本身亦是按照设计模式精心打造,这使得我们可以在开发环境中安心的集成Spring框架,不必担心Spring是如何在后台进行工作的. Spring框架至今已集成了20多个模块.这些模块主要被分如下图所示的核心容器.数据访问/集成,.Web.AOP(面

Spring基础系列10 -- Spring AOP-----------Pointcut, Advisor

Spring基础系列10 -- Spring AOP-----------Pointcut, Advisor 转载:http://www.cnblogs.com/leiOOlei/p/3557643.html 上一篇的Spring AOP Advice例子中,Class(CustomerService)中的全部method都被自动的拦截了.但是大多情况下,你只需要一个方法去拦截一两个method.这样就引入了Pointcut(切入点)的概念,它允许你根据method的名字去拦截指定的method

Spring知识点回顾(01)

Spring知识点回顾(01) 一.依赖注入 1.声明Bean的注解 @Component @Service @Repository @Controller 2.注入Bean的注解 @Autowired @Inject @Resource 二.加载Bean 1.xml方式 - applicationcontext.xml : Beans, Bean, Component-Scan 2.注解方式 - @Configuration,@ComponentScan,@Bean 用@Configurati

【DAY26】JAVA 基础回顾

基础回顾 ---------------- 1.跨平台 os JVM : sandbox 1995 2.基本数据类型 byte //1 -128 ~ 127 short //2 -32768 - 32767 int //4 long //8 float //4 doule //8 char //2 boolean //1 3.引用类型 [] class interface 4.运算符 && //短路 || //短路 & // | // ^ //抑或,相同0,不同为1 >>

Spring基础系列11 -- 自动创建Proxy

Spring基础系列11 -- 自动创建Proxy 转载:http://www.cnblogs.com/leiOOlei/p/3557964.html 在<Spring3系列9- Spring AOP——Advice>和<Spring3系列10- Spring AOP——Pointcut,Advisor拦截指定方法>中的例子中,在配置文件中,你必须手动为每一个需要AOP的bean创建Proxy bean(ProxyFactoryBean). 这不是一个好的体验,例如,你想让DAO层

Spring基础系列12 -- Spring AOP AspectJ

Spring基础系列12 -- Spring AOP AspectJ 转载:http://www.cnblogs.com/leiOOlei/p/3613352.html 本文讲述使用AspectJ框架实现Spring AOP. 再重复一下Spring AOP中的三个概念, Advice:向程序内部注入的代码. Pointcut:注入Advice的位置,切入点,一般为某方法. Advisor:Advice和Pointcut的结合单元,以便将Advice和Pointcut分开实现灵活配置. Aspe

Spring基础系列8 -- Spring自动装配bean

Spring基础系列8 -- Spring自动装配bean 转载:http://www.cnblogs.com/leiOOlei/p/3548290.html 1.      Auto-Wiring ‘no’ 2.      Auto-Wiring ‘byName’ 3.      Auto-Wiring ‘byType 4.      Auto-Wiring ‘constructor’ 5.      Auto-Wiring ‘autodetect’ Spring Auto-Wiring Be

Spring基础系列7 -- 自动扫描组件或者bean

Spring基础系列7 -- 自动扫描组件或者bean 转载:http://www.cnblogs.com/leiOOlei/p/3547589.html 一.      Spring Auto Scanning Components —— 自动扫描组件 1.      Declares Components Manually——手动配置component 2.      Auto Components Scanning——自动扫描组件 3.      Custom auto scan comp