一、IDEA中设置类注释模版的路径
路径:IntelliJ IDEA-->Preferences-->Editor-->File and Code Templates-->Files, 参照如下图:
IntelliJ IDEA-->Preferences-->Editor-->File and Code Templates-->Files
Files-->Class
⚠️注意:生成的标签,如果提示wrong tag的警告,可以选中一个标签,然后option+enter键 add tag to custorm tags --> Fix all 就OK了。
类配置内容如下:
/**
*@ClassName ${NAME}
*@Description 请描述类的业务用途
*@Author ${USER}
*@Date ${DATE} ${TIME}
*@Version 1.0
**/
二、IDEA中设置方法注释模版的路径
路径:IntelliJ IDEA-->Preferences-->Editor-->Live Templates, 参照如下图:
IntelliJ IDEA-->Preferences-->Editor-->Live Templates
设置新的组名:userDefine
因为IDEA生成注释的默认方式是:/*+模板名+快捷键(比如若设置模板名为add快捷键用Tab,则生成方式为
/*add+Tab),如果不采用这样的生成方式IDEA中没有内容的方法将不可用,例如获取方法参数的methodParameters()、
获取方法返回值的methodReturnType()
创建模版
生效范围选择Java就行
编辑模版中的变量
编辑模版中的变量
其中,param的配置建议使用groovy脚本,如下:
groovyScript("if("
{_1}".replaceAll('[\\[|\\]|\\s]', '').split(',').toList();for(i = 0; i < params.size(); i++) {if(i<(params.size()-1)){result+=' * @param ' + params[i] + ' ' + params[i] + '\n'}else{result+=' * @param ' + params[i] + ' '+ params[i] }}; return result;}", methodParameters());
生成方法效果如下:
生成效果