Java如何在Spring中连接/注入null值?
要将null值连接或注入到bean中,我们可以使用<null>元素。下面的配置向您展示了如何在Spring配置文件中进行配置。null例如,当您要覆盖自动连线到Bean中的值时,可能需要连线一个值。
正如您在下面的配置中看到的那样,我们将Bean中的属性writer的值设置song为A,null并且还将两个null值设置到Bean中的songs属性中album。
<?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.xsd">
<bean id="song">
<property name="title" value="I Saw Her Standing There"/>
<property name="writer">
<null/>
</property>
</bean>
<bean id="album">
<property name="title" value="Please Please Me"/>
<property name="year" value="1963"/>
<property name="songs">
<list>
<ref bean="song"/>
<null/>
<null/>
</list>
</property>
</bean>
</beans>
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短