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 送给学长毕业祝福语简短