开发者

Using Ternary operator to pass a parameter in spring configuration

开发者 https://www.devze.com 2023-02-06 07:22 出处:网络
I wish to know if there is a way of passing a parameter conditionally while defining a spring bean. More specifically, I am trying to create a util:map with two entries, the entries are dependent on s

I wish to know if there is a way of passing a parameter conditionally while defining a spring bean. More specifically, I am trying to create a util:map with two entries, the entries are dependent on system properties as defined below:

 <util:map id="queryParameterMap">
    <entry key="star开发者_如何学PythontDate" value="${startdate}"/>
    <entry key="endDate" value="${enddate}"/>
</util:map>

if the system parameter is not set, the value in the map should be defaulted to null. How can this be done? I have tried using spring expression language but that was not of much help.

Regards, Daya


Have you tried #{systemProperties['enddate']}? It does exactly what you want.


PropertyPlaceholderConfigurer probably has the option to set unresolved properties to null. Apart from that, SpEL supports supports defaults. What have you tried?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号