設(shè)置非空判斷,避免后臺返回數(shù)據(jù)為null時匙姜,出現(xiàn)空指針異常閃退畅厢!
在實體類里面右鍵 -> Generate ->就出現(xiàn)下面的頁面
一、第一步
二氮昧、第二步
三框杜、使用此模板生成的效果圖
四、模板代碼
//--------------get --------------------------------
#if($field.modifierStatic)
static ##
#end
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.boolean && $field.primitive)
#if ($StringUtil.startsWithIgnoreCase($name, 'is'))
#set($name = $StringUtil.decapitalize($name))
#else
is##
#end
#else
get##
#end
${name}() {
#if ($field.string)
return $field.name == null ? "" : $field.name;
#else
#if ($field.list)
if ($field.name == null) {
return new ArrayList<>();
}
return $field.name;
#else
return $field.name;
#end
#end
}
//---------------set----------------------------------
#set($paramName = $helper.getParamName($field, $project))
public ##
#if($field.modifierStatic)
static ##
#end
void set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))($field.type $paramName) {
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
#if($field.string)
$field.name = $paramName == null ? "" : $paramName;
#else
$field.name = $paramName;
#end
}