IDEA Getter&Setter方法名snake_case转camelCase
直接贴代码:
Getter设置:
1 #if($field.modifierStatic) 2 static ## 3 #end 4 $field.type ## 5 #set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))) 6 #if ($field.boolean && $field.primitive) 7 #if ($StringUtil.startsWithIgnoreCase($name, 'is')) 8 #set($name = $StringUtil.decapitalize($name)) 9 #else 10 is## 11 #end 12 #else 13 get## 14 #end 15 #set($words = $StringUtil.split($name, "_")) 16 #set($name = "") 17 #foreach($word in $words) 18 #set($name = $name + $StringUtil.capitalize($word)) 19 #end 20 ${name}() { 21 return $field.name; 22 }
Setter设置:
1 #set($paramName = $helper.getParamName($field, $project)) 2 #if($field.modifierStatic) 3 static ## 4 #end 5 #set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))) 6 #set($words = $StringUtil.split($name, "_")) 7 #set($name = "") 8 #foreach($word in $words) 9 #set($name = $name + $StringUtil.capitalize($word)) 10 #end 11 void set$name($field.type $paramName) { 12 #if ($field.name == $paramName) 13 #if (!$field.modifierStatic) 14 this.## 15 #else 16 $classname.## 17 #end 18 #end 19 $field.name = $paramName; 20 }
选择自定义模板,贴上如上所示代码: