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

前端 未结 6 1698
星月不相逢
星月不相逢 2020-12-14 01:28

When using Spring, is it possible to set a property only if the value passed is not null?

Example:


          


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-14 02:06

    You can use default value concept in property configurer in Spring framework as following:

    
       
    
    

    you can set default value by this approach. By this context config if some.param key exist so its value set in abc property and if don't exist your-default-value set in abc property.

    Note: Another benefit of this approah is:"In POJO programming model better approzh is member of class don't have any default value,and default value injected from out of class."

提交回复
热议问题