團隊開發時,業務模塊分配的越清晰,代碼註釋管理越完善,越有利於後面維護,後面再管理也方便很多。另外也起着"文字磚"的做用,你懂的。註釋不須要很詳細,把代碼塊方法塊功能簡述一下就行。否則三月後回頭看就要罵人了,罵完發現是本身寫的,嘖嘖嘖...java
三種經常使用的 Java 註釋方式函數
// 聲明常量 int number;
/* * 類主函數 */ public static void main(String[] args) { }
/** * @param masterId 品牌商Id * @param shopId 店鋪Id * @param skuId 商品skuId * @description: 校驗商品標識碼與店鋪的所屬關係 * @return: net.jdcloud.APIECRM.model.ValidateSkuUsingGETResponse * @author: niaonao * @date: 2020/01/13 */ public static ValidateSkuUsingGETResponse validateSkuUsing(String masterId, String shopId, String skuId){ return null; }
菜單路徑 File-Settings-Editor-File and Code Templates-Incudes-File Header 下添加註釋模板,配置模板後點擊 Apply OK 應用。spa
自定義註釋模板code
/** * @className: ${NAME} * @description: TODO 類描述 * @author: niaonao * @date: ${DATE} **/
新建接口文件自動生成註釋,效果以下對象
/** * @className: CrowdService * @description: 人羣對象業務 * @author: niaonao * @date: 2020/1/13 **/ public interface CrowdService { }
預約義變量 | 描述信息 |
---|---|
${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 |
菜單路徑 File-Settings-Editor-Live Templates 下添加一個新模板組,名字自定義 JavaTemplateGroup。選中模板組,右側點擊新增按鈕,建立新模板。blog
* $param$ * @description: TODO * @return: $return$ * @author: niaonao * @date: $date$ */
Edit variables 編輯變量接口
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,點擊 Define 選中 Java 便可。ip
此處 Expend With 配置爲 Enter 回車鍵,註釋生成快捷方式,看我的習慣,也能夠時 Tab 鍵。開發
點擊 Apply OK 應用配置便可。效果以下rem
/** * @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; }
方法註釋模板不可用在,方法外,若用在方法外 @param 獲取不到,註釋爲 @param null;
類註釋模板在文件建立時生成,已建立文件不會觸發該模板,會觸發方法註釋模板。
Power By niaonao, The End, Thanks