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
通過定義模板,可以完全自定義自己的類注釋