if (!"".equals(crmKhDTO.getDsdlzh())) {
crmKhSwkzxxDTO.setDsdlzh(crmKhDTO.getDsdlzh());
}
能预防crmKhDTO.getDsdlzh()
空指针问题
if(crmKhDTO.getDsdlzh().equals("")){
crmKhSwkzxxDTO.setDsdlzh(crmKhDTO.getDsdlzh());
}
若crmKhDTO.getDsdlzh()
为null
,会报空指针
注意对象要放在后边
if(StringUtils.isEmpty(jcdzOrder.getIsNeedRecepit()) || "".equals(jcdzOrder.getIsNeedRecepit())|| "Y".equals(jcdzOrder.getIsNeedRecepit()))
测试方法:
public static void main(String[] args) {
String a = "aa";
String b = null;
String c = "";
String d = " " ;
String e ;
System.out.println(StringUtils.isEmpty(a));
System.out.println(StringUtils.isEmpty(b));
System.out.println(StringUtils.isEmpty(c));
System.out.println(StringUtils.isEmpty(d));
//System.out.println(StringUtils.isEmpty(e));
System.out.println();
System.out.println("".equals(a));
System.out.println("".equals(b));
System.out.println("".equals(c));
System.out.println("".equals(d));
//System.out.println("".equals(e));
}
结果:
false
true
true
false
false
false
true
false