类注释模板
- 新建类时自动生成在类名上方。
打开设置位置
打开设置,进入如下路径。
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$
*/
设置参数
- 如图所示,模板中写入参数
p
a
r
a
m
param
param 等,点击Edit variables,打开参数设置,配置参数数据源。
设置注释的使用范围
使用方式
- 在java代码中输入 /** 然后敲击Tab按键,生成如下
/**
*
* 功能描述:
*
* @param:
* @return:
* @auther: Administrator
* @date: 2019/12/11 16:27
*/