類註釋模板
- 新建類時自動生成在類名上方。
打開設置位置
打開設置,進入如下路徑。
File–>Settings–>Editor–>File and Code Templates–>Includes–>File Header
設置類註釋模板內容
- 在上圖右邊編輯框,編寫自己的模板即可。例如:
/**
* @Auther: ${USER}
* @Date: ${DATE} ${HOUR}:${MINUTE}
* @Description:
*/
- 注1:上圖上方Scheme是模板的生效範圍。
- 注2:可選變量在description有介紹。
變量 | 註釋 |
---|---|
${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 |
自定義註釋模板
Idea沒有可以直接設置方法註釋模板的地方,可以借用
打開設置位置
打開設置,進入如下路徑。
File–>Settings–>Editor–>Live Templates
創建註釋模板
- 先點擊綠色加號,選擇Template Group,新建一個自己的模板組,如圖命名爲myGroup。
- 然後在自己的莫班組,點擊綠色加號,選擇Live Template,打開模板設置頁面
- 然後填好Abbreviation(快捷輸入),Description(描述)和模板內容(圖中模板如下)
/**
* 功能描述:
* @param: $param$
* @return: $return$
* @auther: $user$
* @date: $date$ $time$
*/
設置參數
- 如圖所示,模板中寫入參數 等,點擊Edit variables,打開參數設置,配置參數數據源。
設置註釋的使用範圍
使用方式
- 在java代碼中輸入 /** 然後敲擊Tab按鍵,生成如下
/**
*
* 功能描述:
*
* @param:
* @return:
* @auther: Administrator
* @date: 2019/12/11 16:27
*/