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

前端 未结 6 1693
星月不相逢
星月不相逢 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:14

    You can create a Utility class that will act as a Factory class for some.Type, and wrap the logic there

    For Example :

    public class TypeFactory {
        public static Type craeteType(SomeType param){
            Type t = new Type();
            if(param!=null)
                t.setParam(param);
        }
    }
    

    and on XML configure the bean creation using this Factory method

    
          
    
    

提交回复
热议问题