Alt + Insert, 调出快捷菜单后选择 Getter and Setter
2 选择 Getter and Setter 后会到如下界面
3 如下图,点击右边第①步,然后第②步点击+号,添加模板,第③步是添加模板内容
4 模板内容如下
Getter :
public ##
#if($field.modifierStatic)
static ##
#end
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.boolean)
#if ($StringUtil.startsWithIgnoreCase($name, 'is'))
#set($name = $StringUtil.decapitalize($name))
#else
is##
#end
#else
get##
#end
${name}() { return $field.name; }
Setter:
#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
$field.name = $paramName;return this;
}
5 最后一步, 修改Settings / Editor / Code Style / Java / Wrapping and Braces 下, 勾选Keep when reformatting下的"Simple methods in one line"