idea设置新建文件模版添加自定义注释

1、前言

今天换了idea的2019.1版本,以前的注释模版不见了,去百度,有点强迫症,都是各种复制来的,还是只有截图不贴模版那种。

2、模版变量

模版位置 Settings->Editor->File and Code Templates下:
在这里插入图片描述
java 的描述如下:

This is a built-in template used each time you create a new Java class, by selecting New | Java Class | Class from the popup menu in one of the project views. The template is editable. Along with Java expressions and comments, you can also use predefined variables (listed below) that will then be expanded like macros into the corresponding values. It is also possible to specify an arbitrary number of custom variables in the format ${<VARIABLE_NAME>}. In this case, before the new file is created, you will be prompted with a dialog where you can define particular values for all custom variables. Using the #parse directive, you can include templates from the Includes tab, by specifying the full name of the desired template as a parameter in quotation marks. For example: #parse("File Header.java") 
Predefined variables will take the following values:
${PACKAGE_NAME}
 
name of the package in which the new class is created
${NAME}
 
name of the new class specified by you in the Create New Class dialog
${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
${HOUR}
 
current hour
${MINUTE}
 
current minute
${PROJECT_NAME}
 
the name of the current project
 Apache Velocity template language is used

翻译:

这是一个内置的模版,用来给你每次新建java类,通过选择项目视图里面的右键菜单选项new->Java Class来新建。这个模版是可编辑的。属于java表达式和注释,你也可用使用预定于的变量(下面已列出)这会像宏一样展开为相应的值。也可以指定任意数量的自定义变量,用这样格式${<VARIABLE_NAME>}。在这个例子中,在一个文件被创建之前,系统将提示您一个对话框,您可以在其中为所有自定义变量定义特定值。用#parse这个指令,你可以导入模版通过Includes tab栏通过在引号中指定所需模板的全名作为参数。
例如: #parse(“File Header.java”)
预定于的变量有如下取值:
${PACKAGE_NAME}
新建类的包名
${NAME}
新建类的名字,通过新建class的弹窗中设置
${USER}
系统当前的登录名
${DATE}
系统当前的日期
${TIME}
系统当前的时间
${YEAR}
今年
${MONTH}
当前
${MONTH_NAME_SHORT}
月份名单词前3个字母。比如:Jan、Feb等
${MONTH_NAME_FULL}
月份的全名。例如:January、February等
${DAY}
当月的天
${HOUR}
当前小时数
${MINUTE}
当前分钟数
${PROJECT_NAME}
当前项目名字
使用了Apache Velocity模板语言

3、添加模版

java模版:

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} {
}

通过翻译描述文件可知Includes tab下可配置解析的模版,所以我把模版写在File Header中:
在这里插入图片描述

我的目的很简单,加个作者和创建日期即可,所以我的模版如下:


/**
 * @author HitvzByHui
 *  date ${YEAR}-${MONTH}-${DAY}
 */

作者写死即可,不用登陆名,用${DATE}变量不是我要的格式,干脆用几个时间变量拼成自己要的格式。

效果如下:
在这里插入图片描述
以上即是全部。

另一种方法,不在Includes tab下写也是可以的,就是最简单的在想要的模版添加自己要的注释即可,比如:
在这里插入图片描述
但你每个java后缀的文件模版都要添加一次,觉得麻烦只添加class和interface就好了。

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值