<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<!--
配置HelloWorld所对应的bean,即将HelloWorld的对象交给Spring的IOC容器管理
通过bean标签配置IOC容器所管理的bean
属性:
id:设置bean的唯一标识
class:设置bean所对应类型的全类名
-->
<bean id="studentOne" class="com.zqt.spring.pojo.Student"></bean>
setter注入
<!--setter注入-->
<bean id="studentTwo" class="com.zqt.spring.pojo.Student">
<property name="sId" value="1001"></property>
<property name="sName" value="张三"></property>
<property name="age" value="18"></property>
<property name="gender" value="男"></property>
</bean>
构造器注入
<!--构造器注入-->
<bean id="studentThree" class="com.zqt.spring.pojo.Student">
<constructor-arg value="1002"></constructor-arg>
<constructor-arg value="李四"></constructor-arg>
<constructor-arg value="女"></constructor-arg>
<constructor-arg value="16" name="age"></constructor-arg>
</bean>
特殊值:null值,XML实体,CDATA
<!--特殊值:null值,XML实体,CDATA-->
<bean id="studentFour" class="com.zqt.spring.pojo.Student">
<property name="sId" value="1003"></property>
<!-- <property name="sName" value="<王五>"></property>-->
<property name="sName" >
<value><![CDATA[<王五>]]></value>
</property>
<property name="gender">
<null />
</property>
</bean>
关于类的类型赋值
<!--关于类的类型赋值-->
<bean id="studentFive" class="com.zqt.spring.pojo.Student">
<property name="sId" value="1004"></property>
<property name="sName" value="赵六"></property>
<property name="age" value="26"></property>
<property name="gender" value="女"></property>
<!--级联-->
<!-- <property name="clazz" ref="clazzOne"></property>-->
<!-- <property name="clazz.clazzId" value="1111"></property>-->
<!-- <property name="clazz.clazzName" value="最轻王者班"></property>-->
<property name="clazz">
<!--内部bean-->
<bean id="clazzInner" class="com.zqt.spring.pojo.Clazz">
<property name="clazzId" value="1111"></property>
<property name="clazzName" value="最强王者班"></property>
</bean>
</property>
<!--关于类的类型赋值-->
<bean id="clazzOne" class="com.zqt.spring.pojo.Clazz">
<property name="clazzId" value="1111"></property>
<property name="clazzName" value="最强王者班"></property>
</bean>
关于数组类型赋值
<!--关于数组类型赋值-->
<bean id="studentThree" class="com.zqt.spring.pojo.Student">
<property name="sId" value="1004"></property>
<property name="sName" value="赵六"></property>
<property name="age" value="26"></property>
<property name="gender" value="女"></property>
<property name="hobby">
<array>
<value>抽烟</value>
<value>喝酒</value>
<value>烫头</value>
</array>
</property>
</bean>
关于list类型赋值
<!--关于list类型赋值-->
<bean id="studentThree" class="com.zqt.spring.pojo.Student">
<property name="sId" value="1004"></property>
<property name="sName" value="赵六"></property>
<property name="age" value="26"></property>
<property name="gender" value="女"></property>
<!--list类型1-->
<property name="students">
<list>
<ref bean="studentOne"></ref>
<ref bean="studentTwo"></ref>
<ref bean="studentThree"></ref>
</list>
</property>
<!--list类型2-->
<property name="students" ref="studentList"></property>
</bean>
<!--list类型2:配置集合的bean,需要使用util的约束-->
<util:list id="studentList">
<ref bean="studentOne"></ref>
<ref bean="studentTwo"></ref>
<ref bean="studentThree"></ref>
</util:list>
关于map类型赋值
<bean id="studentFive" class="com.zqt.spring.pojo.Student">
<property name="sId" value="1004"></property>
<property name="sName" value="赵六"></property>
<property name="age" value="26"></property>
<property name="gender" value="女"></property>
<!--map类型1-->
<property name="teacherMap" ref="teacherMap"></property>
<!--map类型2-->
<property name="teacherMap">
<map>-->
<entry key="1021" value-ref="teacherOne"></entry>
<entry key="1022" value-ref="teacherTwo"></entry>
</map>
</property>
</bean>
<bean id="teacherOne" class="com.zqt.spring.pojo.Teacher">
<property name="tid" value="1021"></property>
<property name="tname" value="赵无极"></property>
</bean>
<bean id="teacherTwo" class="com.zqt.spring.pojo.Teacher">
<property name="tid" value="1022"></property>
<property name="tname" value="张三丰"></property>
</bean>
<!--map类型1-->
<util:map id="teacherMap">
<entry key="1021" value-ref="teacherOne"></entry>
<entry key="1022" value-ref="teacherTwo"></entry>
</util:map>