Spring中几种属性的配置

<?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-3.2.xsd">
	<bean id="car1" class="com.spring3.Car">
		<constructor-arg value="奥迪" index="0"></constructor-arg>
		<constructor-arg value="上海" index="1"></constructor-arg>
		<constructor-arg type="double">
			<value>4525.25</value>
		</constructor-arg>
	</bean>
	<bean id="car2" class="com.spring3.Car">
		<constructor-arg value="宝马s" index="0"></constructor-arg>
		<constructor-arg value="北京" index="1"></constructor-arg>
		<constructor-arg type="int">
			<value>4848</value>
		</constructor-arg>
	</bean>
	<!-- 对集合属性赋值 -->
	<bean id="persont" class="com.spring3.Person">
		<property name="name" value="张小风"></property>
		<property name="age" value="25"></property>
		<property name="car">
		<!-- 对集合属性赋值 -->
			<list>
				<ref bean="car1" />
				<ref bean="car2" />
				<bean id="car1" class="com.spring3.Car">
					<constructor-arg value="奔驰" index="0"></constructor-arg>
					<constructor-arg value="上海" index="1"></constructor-arg>
					<constructor-arg value="125815.25" type="double"></constructor-arg>
				</bean>
			</list>
		</property>
	</bean>
	<!-- 配置Map的属性值 -->
	<bean id="newpersont" class="com.spring3.NewPerson">
		<property name="name" value="刘玉华"></property>
		<property name="age" value="20"></property>
		<property name="car">
			<map>
				<entry key="noe" value-ref="car1"></entry>
				<entry key="tow" value-ref="car2"></entry>
			</map>
		</property>
	</bean>
	<!-- 使用 properties 配置-->
	<bean id="pro" class="com.spring3.Pro">
		<property name="properties">
			<props>
				<prop key="user">root</prop>
				<prop key="password">123</prop>
				<prop key="jdbcUrl">jdbc:mysql:///test</prop>
			</props>
		</property>
	</bean>
	<!-- 使用单列的集合 bean 以供多个bean 进行引用 -->
	<util:list id="cars">
		<ref bean="car1"/>
		<ref bean="car2"/>
	</util:list>
	
	<bean  id="person4" class="com.spring3.Person">
		<property name="name" value="kkk"></property>
		<property name="age" value="225"></property>
		<property name="car" ref="cars"/>
	</bean>
	<!-- 通过 p命名空间 为bean 赋值  需要导入 p 的命名空间 -->
	<bean id="person5" class="com.spring3.Person" p:name="不要" 
	p:age="30" p:car-ref="cars"></bean>
</beans>
只提供了配置文件,需要原文件的请给我留言
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值