一、live template

在IDEA中,系统已经帮我们定义好了许多的代码模板,我们只需要在代码中敲对应的模板指令,就可以生成对应的代码模板。按“CTRL + ALT+ S”打开“setting”,然后依次选择“Editor -> live template”,即可在下图标注的地方查看所有的模板指定:

IDEA代码模板

IDEA代码模板

二、自定义live template

比如说我们写代码时都会输出对应的日志,那么输出日志就需要在类中添加这段代码“public final Logger log = LoggerFactory.getLogger(UserController.getClass());”,那我们就可以将这段代码定义成一个模板代码,添加方法如下:

IDEA代码模板

IDEA代码模板 

IDEA代码模板 IDEA代码模板

IDEA代码模板 IDEA代码模板

IDEA代码模板 最后点击“OK”即可自定义模板成功。

三、postfix

postfix和live template差不多,但是要比live template更加的方便,但是postfix不能自定义,只能使用系统定义好的。postfix是表达式加点号加代码模板指令,而live template是直接输入模板指令,查看postfix的方法,按“CTRL + ALT + S”打开“setting”,然后依次如下图所示点击对应的选项进行postfix查看:

IDEA代码模板

相关文章:

  • 2021-11-26
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2021-04-16
  • 2021-10-31
  • 2021-08-06
  • 2021-11-24
猜你喜欢
  • 2021-04-01
  • 2021-12-28
  • 2021-12-04
  • 2021-07-12
  • 2021-06-24
  • 2021-07-19
  • 2021-11-15
相关资源
相似解决方案