IOC依赖注入(各种类型的传值)

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"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans 
	                       http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
	                    
	              
          <!-- IOC依赖注入如何在容器中传值,下面我们用到的bean中的属性之前也说了这里就不解释,我们直接用 -->
          
          <!-- 基本类型或string -->
          <bean id="student" clss="spring.Student">
          		<property name="id" value="100"></property>
          		<property name="username" value="张三"></property>
          		
          		<!-- 赋空值/赋null-->
          		<property name="telepehone" vlaue=""></property>
          		<property name="telepehone">
          				<null></null>
          		</property>
          		
          		<!-- 引用类型 -->
          		<property name="stuClass" ref="stuClass"></property>
          		
          		<!-- 数组-->
          		<property name="hobbies">
          				<array>
          					<value>打王者</value>
          					<value>打王牌</value>
          					<value>打大哥</value>
          				</array>
          		</property>
          		
          		<!--List集合(基本类型似例如:list<String>):有序允许重复-->
          		<property name="scores">
          				<list>
          					<value>打王者</value>
          					<value>打王牌</value>
          					<value>打大哥</value>
          				</list>
    			</property>
    			<!--List集合(引用类型似例如:list<StuClass>):有序允许重复-->
    			<property name="list">
    				<list>
    					<ref bean="stuClass"></ref>
    				</list>
    			
    			</property>
    			
    			<!-- set集合 :(基本类型例如:set<String>)无序,不允许重复-->
    			<property name="scores">
          				<set>
          					<value>打王者</value>
          					<value>打王牌</value>
          					<value>打大哥</value>
          				</set>
    			</property>
    			<!--set集合 :(引用类型例如:set<StuClass>)无序,不允许重复-->
    			<property name="set">
    				<set>
    					<ref bean="stuClass"></ref>
    				</set>
    			
    			</property>
    			<!-- Map集合 ,会覆盖重复的key-->
    			<property name="map">
    				<map>
    					<entry key="JAVA" value="100"></entry>
    					<entry key="PHP" value="100"></entry>
    					<entry key="PYTHON" value="100"></entry>
    				</map>
    			</property>
    			
    			<!-- Properties类型 -->
    			<property name="properties">
    				<props>
    					<prop key="username">scott</prop>
    					<prop key="password">123456</prop>
    				</props>
    			
    			</property>
          </bean>
          <bean id="stuClass" class="spring.StuClass">
          		<constructor-arg name="id" value="666"></constructor-arg>
          		<constructor-arg name="name" value="Java课程"></constructor-arg>
          </bean>              
</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值