application.xml file code

1.application.xml file - basic code

<?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. The way of set injection

(1) Ordinary value injection -value

<bean id="student" class="com.kuang.pojo.Student">
	<!--第一种: 普通值注入,使用value属性-->
    <property name="name" value="婉婉"/>
</bean>

(2) bean injection-ref

bean injection is used when using reference types

<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) Array injection

 	  <!--第三种:数组注入-->
      <property name="books">
          <array>
              <value>红楼梦</value>
              <value>西游记</value>
              <value>水浒传</value>
              <value>三国演义</value>
          </array>
      </property>

(4) list injection

	  <!--第四种:list-->
      <property name="hobbys">
          <list>
              <value>听歌</value>
              <value>看电影</value>
          </list>
      </property>

(5) Map injection

	  <!--第五种:给map类型注入值-->
      <property name="card">
          <map>
              <entry key="180" value="晓晓" />
              <entry key="181" value="晓晓1" />
              <entry key="182" value="晓晓2" />
          </map>
      </property>

(6) Set injection

	  <!--第六种:给set类型注入值-->
      <property name="games">
          <set>
              <value>王者</value>              <value>王者</value>
              <value>吃鸡</value>
          </set>
      </property>

(7) Null value injection

<!--第七种:null值注入-->
      <property name="wife">
          <null/>
      </property>

(8) Null value injection

 	  <!--第八种:空值注入-->
      <property name="wife" value="" />

(9) Property value injection (ie Properties value injection)

	  <!--第九种:Properties值注入-->
      <property name="info">
          <props>
              <prop key="学号">12342</prop>
              <prop key="性别"></prop>
              <prop key="年龄">15</prop>
          </props>
      </property>

Guess you like

Origin blog.csdn.net/Silly011/article/details/124035494