123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?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 https://www.springframework.org/schema/util/spring-util.xsd">
- <bean id="studentOne" class="com.cdxw.spring.pojo.Student"></bean>
- <bean id="studentTwo" class="com.cdxw.spring.pojo.Student">
- <!--
- property:通过成员变量的set方法进行赋值
- name:设置需要赋值的属性名(和set方法有关)
- value:设置为属性所赋的值
- -->
- <property name="sid" value="1001"></property>
- <property name="sname" value="张三"></property>
- <property name="age" value="23"></property>
- <property name="gender" value="男"></property>
- </bean>
- <bean id="studentThree" class="com.cdxw.spring.pojo.Student">
- <constructor-arg value="1002"></constructor-arg>
- <constructor-arg value="李四"></constructor-arg>
- <constructor-arg value="24"></constructor-arg>
- <constructor-arg value="女"></constructor-arg>
- </bean>
- <bean id="studentFour" class="com.cdxw.spring.pojo.Student">
- <property name="sid" value="1003"></property>
- <property name="sname" value="王五"></property>
- <property name="gender">
- <null/>
- </property>
- </bean>
- <bean id="studentFive" class="com.cdxw.spring.pojo.Student">
- <property name="sid" value="1003"></property>
- <!--
- <:<
- >:>
- CDATA节其中的内容会原样解析<![CDATA[ ... ]]>
- CDATA节是xml中一个特殊的标签,因此不能写在一个属性中,只能以
- 标签的形式来使用
- -->
- <property name="sname" value="<王五>"></property>
- </bean>
- <bean id="studentSix" class="com.cdxw.spring.pojo.Student">
- <property name="sid" value="1003"></property>
- <property name="sname">
- <value><![CDATA[<王五>]]></value>
- </property>
- <property name="gender">
- <null/>
- </property>
- </bean>
- <bean id="studentSeven" class="com.cdxw.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>
- <!--ref:引用IOC容器中的某个bean的id,将对应的bean为属性赋值-->
- <property name="clazz" ref="clazzOne"></property>
- </bean>
- <bean id="clazzOne" class="com.cdxw.spring.pojo.Clazz">
- <property name="cid" value="1111"></property>
- <property name="cname" value="最强王者班"></property>
- <property name="students">
- <list>
- <ref bean="studentOne"></ref>
- <ref bean="studentTwo"></ref>
- <ref bean="studentThree"></ref>
- </list>
- </property>
- </bean>
- <bean id="studentEight" class="com.cdxw.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>
- <!--ref:引用IOC容器中的某个bean的id,将对应的bean为属性赋值-->
- <property name="clazz" ref="clazzOne"></property>
- <!--级联的方式,要保证提前为clazz属性赋值或者实例化-->
- <!-- <property name="clazz.cid" value="2222"></property>-->
- <!-- <property name="clazz.cname" value="远大前程班"></property>-->
- </bean>
- <bean id="studentNine" class="com.cdxw.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">
- <!--内部bean,只能在当前bean的内部使用,不能直接通过IOC容器获取-->
- <bean id="clazzInner" class="com.cdxw.spring.pojo.Clazz">
- <property name="cid" value="3333"></property>
- <property name="cname" value="宇宙第一班"></property>
- </bean>
- </property>
- <property name="hobby">
- <array>
- <value>抽烟</value>
- <value>喝酒</value>
- <value>烫头</value>
- </array>
- </property>
- </bean>
- <!--配置一个集合类型的bean,需要使用util的约束-->
- <util:list id="studentList">
- <ref bean="studentOne"></ref>
- <ref bean="studentTwo"></ref>
- <ref bean="studentThree"></ref>
- </util:list>
- <bean id="clazzTwo" class="com.cdxw.spring.pojo.Clazz">
- <property name="cid" value="1111"></property>
- <property name="cname" value="最强王者班"></property>
- <property name="students" ref="studentList"></property>
- </bean>
- <bean id="studentTen" class="com.cdxw.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">
- <!--内部bean,只能在当前bean的内部使用,不能直接通过IOC容器获取-->
- <bean id="clazzInner" class="com.cdxw.spring.pojo.Clazz">
- <property name="cid" value="2222"></property>
- <property name="cname" value="远大前程班"></property>
- </bean>
- </property>
- <property name="hobby">
- <array>
- <value>抽烟</value>
- <value>喝酒</value>
- <value>烫头</value>
- </array>
- </property>
- <property name="teacherMap">
- <map>
- <!--一个entry表示一个键值对-->
- <entry key="10086" value-ref="teacherOne"></entry>
- <entry key="10010" value-ref="teacherTwo"></entry>
- </map>
- </property>
- </bean>
- <!--配置teacher类的bean-->
- <bean id="teacherOne" class="com.cdxw.spring.pojo.Teacher">
- <property name="tid" value="10086"></property>
- <property name="tname" value="大宝"></property>
- </bean>
- <bean id="teacherTwo" class="com.cdxw.spring.pojo.Teacher">
- <property name="tid" value="10010"></property>
- <property name="tname" value="小宝"></property>
- </bean>
- <bean id="studentEleven" class="com.cdxw.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">
- <!--内部bean,只能在当前bean的内部使用,不能直接通过IOC容器获取-->
- <bean id="clazzInner" class="com.cdxw.spring.pojo.Clazz">
- <property name="cid" value="2222"></property>
- <property name="cname" value="远大前程班"></property>
- </bean>
- </property>
- <property name="hobby">
- <array>
- <value>抽烟</value>
- <value>喝酒</value>
- <value>烫头</value>
- </array>
- </property>
- <property name="teacherMap" ref="teacherMap"></property>
- </bean>
- <util:map id="teacherMap">
- <entry key="10086" value-ref="teacherOne"></entry>
- <entry key="10010" value-ref="teacherTwo"></entry>
- </util:map>
- <bean id="studentTwelve" class="com.cdxw.spring.pojo.Student"
- p:sid="1005" p:sname="小明" p:teacherMap-ref="teacherMap"></bean>
- </beans>
|