zoukankan      html  css  js  c++  java
  • 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} {
    }
    
    

    系统变量类型

    ${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

    效果

    新建一个类,Test

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

  • 相关阅读:
    ContextLoaderListener和Spring MVC中的DispatcherServlet学习 随手记
    Linux目录详解
    9---PIP 管理工具的使用
    8. Python自定义模块humansize
    1. Hyper上的CentOS 6.5 网络配置
    Python基础学习8---list列表的操作
    Python基础学习6---存储器
    Python基础学习3---数据结构
    Python基础学习2---模块
    Python基础学习1---函数
  • 原文地址:https://www.cnblogs.com/jason0529/p/13606595.html
Copyright © 2011-2022 走看看