如何在idea里创建注释模版

✅ 步骤:创建一个类注释的 Live Template(缩写为 cls)
① 打开设置
IDEA 菜单栏点击:File > Settings(或按快捷键 Ctrl + Alt + S)

② 进入 Live Templates 设置
在左侧菜单找到:Editor > Live Templates

点击右边的 +(Add)按钮 ➜ 选择 Live Template

③ 填写模板内容
Abbreviation(缩写)填:cls

Description:可以写 类注释模板,方便以后管理

Template text(模板内容)粘贴以下内容:

/**
 * @ClassName: $CLASS_NAME$
 * @Description: $DESCRIPTION$
 * @Author: $USER$
 * @Date: $DATE$ $TIME$
 */

④ 设置变量

变量名 Expression 默认值 / 说明
CLASS_NAME fileNameWithoutExtension() 自动填入当前类名
DESCRIPTION (留空) 你使用时自己填写描述
USER user() 自动填入当前系统用户名
DATE date() 自动填入当前日期
TIME time() 自动填入当前时间

⑤ 设置适用范围
点击右侧的 Define(定义)

勾选:Java(也可以只勾选 Declaration)

⑥ 点击 OK 保存
使用方式(超简单)
在类名前一行,输入 cls

然后按 Tab,注释就自动出来了 ✨

比如在这个地方使用:

java
cls  // ➜ Tab
public class HelloWorld {
}

你就会看到自动展开成:

java
/**
 * @ClassName: HelloWorld
 * @Description: 
 * @Author: cxa
 * @Date: 2025/04/22 16:30
 */
public class HelloWorld {
}```

你可能感兴趣的:(Java学习,intellij-idea,java,ide)