1.application.xml文件-基本代码
<?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
https://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
2.set注入的方式
(1)普通值注入-value
<bean id="student" class="com.kuang.pojo.Student">
<!--第一种: 普通值注入,使用value属性-->
<property name="name" value="婉婉"/>
</bean>
(2)bean注入-ref
使用到引用类型时会用到bean注入
<bean id="student" class="com.kuang.pojo.Student">
<!--第二种:Bean注入,使用ref属性-->
<property name="address" ref="address" />
<bean id="address" class="com.kuang.pojo.Address"/>
</bean>
(3)数组注入
<!--第三种:数组注入-->
<property name="books">
<array>
<value>红楼梦</value>
<value>西游记</value>
<value>水浒传</value>
<value>三国演义</value>
</array>
</property>
(4)list注入
<!--第四种:list-->
<property name="hobbys">
<list>
<value>听歌</value>
<value>看电影</value>
</list>
</property>
(5)Map注入
<!--第五种:给map类型注入值-->
<property name="card">
<map>
<entry key="180" value="晓晓" />
<entry key="181" value="晓晓1" />
<entry key="182" value="晓晓2" />
</map>
</property>
(6)Set注入
<!--第六种:给set类型注入值-->
<property name="games">
<set>
<value>王者</value> <value>王者</value>
<value>吃鸡</value>
</set>
</property>
(7)null值注入
<!--第七种:null值注入-->
<property name="wife">
<null/>
</property>
(8)空值注入
<!--第八种:空值注入-->
<property name="wife" value="" />
(9)属性值注入(即Properties值注入)
<!--第九种:Properties值注入-->
<property name="info">
<props>
<prop key="学号">12342</prop>
<prop key="性别">女</prop>
<prop key="年龄">15</prop>
</props>
</property>