1. 引言
????團(tuán)隊(duì)開發(fā)時(shí)洲脂,業(yè)務(wù)模塊分配的越清晰,代碼注釋管理越完善剧包,越有利于后面維護(hù)恐锦,后面再管理也方便不少。另外也起著"文字磚"的作用疆液,你懂的一铅。注釋不需要很詳細(xì),把代碼塊方法塊功能簡(jiǎn)述一下就行堕油。不然三月后回頭看就要罵人了潘飘,罵完發(fā)現(xiàn)是自己寫的肮之,嘖嘖嘖...
????三種常用的 Java 注釋方式
// 聲明常量
int number;
/*
* 類主函數(shù)
*/
public static void main(String[] args) {
}
/**
* @param masterId 品牌商Id
* @param shopId 店鋪Id
* @param skuId 商品skuId
* @description: 校驗(yàn)商品標(biāo)識(shí)碼與店鋪的所屬關(guān)系
* @return: net.jdcloud.APIECRM.model.ValidateSkuUsingGETResponse
* @author: niaonao
* @date: 2020/01/13
*/
public static ValidateSkuUsingGETResponse validateSkuUsing(String masterId, String shopId, String skuId){
return null;
}
2. 自定義注釋模板
2.1 類注釋模板
2.1.1 配置模板
????菜單路徑 File-Settings-Editor-File and Code Templates-Incudes-File Header 下添加注釋模板,配置模板后點(diǎn)擊 Apply OK 應(yīng)用卜录。
????自定義注釋模板
/**
* @className: ${NAME}
* @description: TODO 類描述
* @author: niaonao
* @date: ${DATE}
**/
????新建接口文件自動(dòng)生成注釋戈擒,效果如下
/**
* @className: CrowdService
* @description: 人群對(duì)象業(yè)務(wù)
* @author: niaonao
* @date: 2020/1/13
**/
public interface CrowdService {
}
2.1.2 自定義注釋模板不完全變量參考表
預(yù)定義變量 | 描述信息 |
---|---|
${NAME} | the name of the current file |
${PACKAGE_NAME} | name of the package in which the new file is created |
${USER} | current user system login name |
${DATE} | current system date |
${TIME} | current system time |
${YEAR} | current year |
${MONTH} | current month |
${MONTH_NAME_SHORT} | first 3 letters of the current month name. Example: Jan, Feb, etc. |
${MONTH_NAME_FULL} | full name of the current month. Example: January, February, etc. |
${DAY} | current day of the month |
${DAY_NAME_SHORT} | first 3 letters of the current day name. Example: Mon, Tue, etc. |
${DAY_NAME_FULL} | full name of the current day. Example: Monday, Tuesday, etc. |
${HOUR} | current hour |
${MINUTE} | current minute |
${PROJECT_NAME} | the name of the current project |
2.2 方法注釋模板
2.2.1 配置模板
????菜單路徑 File-Settings-Editor-Live Templates 下添加一個(gè)新模板組,名字自定義 JavaTemplateGroup艰毒。選中模板組筐高,右側(cè)點(diǎn)擊新增按鈕,創(chuàng)建新模板丑瞧。
- Abbreviation 配置為* 柑土。
- Description 自定義描述信息。
- Template Text 自定義模板
*
$param$
* @description: TODO
* @return: $return$
* @author: niaonao
* @date: $date$
*/
????Edit variables 編輯變量
- 變量 return 表達(dá)式為 methodReturnType()
- 變量 date 表達(dá)式為 date()
- 變量 param 表達(dá)式為
groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {result+='* @param: ' + params[i] + ((i < params.size() - 1) ? '\\n ' : '')};return result", methodParameters())
????若有警告信息 No Applicable contexts绊汹,點(diǎn)擊 Define 選中 Java 即可稽屏。
????此處 Expend With 配置為 Enter 回車鍵,注釋生成快捷方式灸促,看個(gè)人習(xí)慣诫欠,也可以時(shí) Tab 鍵。
????點(diǎn)擊 Apply OK 應(yīng)用配置即可浴栽。效果如下
/**
* @param: masterId
* @param: shopId
* @param: skuId
* @description: TODO
* @return: net.jdcloud.APIECRM.model.ValidateSkuUsingGETResponse
* @author: niaonao
* @date: 2020/1/13
*/
public static ValidateSkuUsingGETResponse validateSkuUsing(String masterId, String shopId, String skuId) {
return null;
}
2.2.2 補(bǔ)充說明
????方法注釋模板不可用在荒叼,方法外,若用在方法外 @param 獲取不到典鸡,注釋為 @param null;
????類注釋模板在文件創(chuàng)建時(shí)生成被廓,已創(chuàng)建文件不會(huì)觸發(fā)該模板,會(huì)觸發(fā)方法注釋模板萝玷。
Power By niaonao, The End, Thanks