一、類名註釋:
打開File->Settings,選擇Editor->File and Code Templates,切換到“Includes”,點擊File Header,
然後錄入以下內容:
/**
* @ProjectName: ${PROJECT_NAME}
* @Package: ${PACKAGE_NAME}
* @ClassName: ${NAME}
* @Author: yf
* @Description: ${description}
* @Date: ${DATE} ${TIME}
*/
二、方法註釋:
打開File->Settings,選擇Editor->Live Templates
點擊新建“+”,新增一個Template Group,命名自定義,我這邊定義的是MyGroup;
選中新建的MyGroup,然後點擊新建“+”,新增一個Live Template,
然後編輯剛剛新增的Live Template,在Template text中錄入以下內容:
*
* @Method $method$
* $VAR1$
$params$* @return $returns$
* @Author yf
* @Desc 描述
* @Date $date$ $time$
*/
然後點擊“Edit variables”,編輯定義的變量:
其中VAR1的腳本爲:
groovyScript(" def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) { if(i!=0)result+= ' * '; result+='@param ' + params[i] + ((i < (params.size() - 1)) ? '\\n' : ''); }; return result", methodParameters())
其餘變量參考上圖。
使用時,在方法上輸入“/*”或者“/**”,然後按住“Tab”鍵即可。