Spring SpEL - 仅当值不为空时才设置 属性

Spring SpEL - set a property only if the value is not null

我正在使用 Spring 并且我想仅在传递的值不为空时设置 属性?

我试过这个例子,但它不起作用。 我只想在 属性 不为空时添加它,否则不添加它。 我不想添加默认值。 感谢您的帮助

<util:properties id="mailProperties" location="classpath:mail.properties"/>
  <property name="javaMailProperties">
        <props>
            <prop key="mail.smtp.starttls.enable">#{mailProperties['mail.smtp.starttls.enable']:''}</prop>             
           </props>
    </property>

我相信你想要这样的东西

${mail.smtp.starttls.enable:defaultValue}

更多详情: Is there a way to specify a default property value in Spring XML?

https://jira.spring.io/browse/SPR-4785

#{mailProperties['mail.smtp.starttls.enable']==null ? false: mailProperties['mail.smtp.starttls.enable']}

这是设置默认值的示例:如果值为空,我将其设置为假,否则我将其设置为其值。