7.4.2 Null and empty string values

Spring treats empty arguments for properties and the like as empty Strings. The following XML-based configuration metadata snippet sets the email property to the empty String value ("").

Spring对待属性中空的参数就像当做空的字符串一样.如下的基于XML配置元数据片段设置email属性为空的字符串("").

<bean class="ExampleBean">
    <property name="email" value=""/>
</bean>

The preceding example is equivalent to the following Java code:

前面的例子等同于下面的Java代码:

exampleBean.setEmail("");

The <null/> element handles null values. For example:

 <null/> 元素处理 null 值.例如:

<bean class="ExampleBean">
    <property name="email">
        <null/>
    </property>
</bean>

The above configuration is equivalent to the following Java code:

上面的配置等同于下面的Java代码:

exampleBean.setEmail(null);

猜你喜欢

转载自blog.csdn.net/weixin_41648566/article/details/80774476