Fork me on GitHub

Idea使用方式——创建类模板

问题:创建类或接口时,要添加自定义的默认注释,比如版本,时间等。每个类修改显然不符合程序员的思路,有没有办法通过定义模板来实现?

使用Idea模板

Idea可听过创建类模板来实现。
功能路径:Setting -> Editor -> File and Code Template -> Class 修改,右侧文件内容

模板内容

${}变量标识变量注入

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")
package ${PACKAGE_NAME};   // 解决package
#end
#parse("File Header.java")
// 默认导入lombok,方便日志打印
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**  
    * @Title: ${NAME}      // 默认是类名称 
    * @Description:        // 类实现的介绍
    * @author: libo        //  作者
    * @date: ${DATE} ${TIME} // 创建时间,${DATE} 自动注入系统日期,${TIME}自动注入当天时间,分钟
    * @Version: 1.0         //版本
    */
@Slf4j
public class ${NAME} {
}

系统变量类型

$ name of the package in which the new class is created
$ name of the new class specified by you in the Create New Class dialog
$ current user system login name
$ current system date
$ current system time
$ current year
$ current month
$ first 3 letters of the current month name. Example: Jan, Feb, etc.
$ full name of the current month. Example: January, February, etc.
$ current day of the month
$ current hour
$ current minute
$ the name of the current project

效果

新建一个类,Test

通过定义模板,可以完全自定义自己的类注释

posted @ 2020-09-03 11:21  龙城飞将军  阅读(1967)  评论(0编辑  收藏  举报