目录
一、注释模板
1.1、类注释
1.1.1、操作路径
1)File > Setting > Editor > File and Code Templates > Includes > File Header > 粘贴注释模板 > Apply > ok
2)参考类注释模板
/**
* @Author: ${USER}
* @Desctription: TODO
* @Date: Created in ${DATE} ${TIME}
* @Version: 1.0
*/
1.1.2、效果
1)新建类时自动生成类注释
package com.example.demo.controller;
/**
* @Author: pandafox
* @Desctription: TODO
* @Date: Created in 2020/6/29 6:57
* @Version: 1.0
*/
public class TestController {
}
1.2、方法注释
1.2.1、操作步骤
1)File > Setting > Editor > Live Templates > +号 > Template Group
2)创建组userDefine
3)选中新建组userDefine > +号 > Live Template
4)新建注释模板,将Abbreviation
设置为*
,将注释模板复制到Tempate Text
中,然后分布对下图中1、2、3标记处进行配置
5)参考方法注释模板(上面没有/
)
*
* @Author $user$
* @Desctription TODO
* @Date $date$ $time$
* @Param $Param$
* @return $return$
*/
6)标记1处 > Define > 勾选Java
7)标注2处 > Edit variables > 配置参数
分别选择变量对应的expression表达式,user对应user()、date对应date()、time对应time()、param对应methodParameters()
8)标注3处 > Expand with > 选择Enter
1.2.2、效果
在方法上面先输入/**
,再按回车键,自动生成对应注释
/**
* @Author pandafox
* @Desctription TODO
* @Date 2020/6/29 7:30
* @Param []
* @return
*/
@RequestMapping("/test")
@ResponseBody
public Map<String, Object> getMsg(){
Map<String, Object> map = new HashMap<>();
map.put("result", "response msg");
return map;
}
二、代码格式化
这里使用Save Actions
插件进行代码格式化
2.1、在线安装
2.1.1、操作步骤
1)File > Settings > Plugins > Marketplace > 搜索 Save actions > Install > 重启IDE
2)File > Settings > Other Settings > Save Action > 勾选如下选项
2.1.2、效果
1)按Ctrl+S
保存代码时,idea会进行自动格式化处理,如tab对齐、去掉未引用的import语句、花括号格式化等
2.2、离线安装
有时候我们可能处于内网环境,无法通过idea完成在线安装,所以需要手动下载安装包进行离线安装
2.2.1、操作步骤
1)访问idea插件库地址:https://plugins.jetbrains.com/
2)搜索 Save Actions
插件
3)version > 选择与idea版本一致的插件 > 点击 Download
(idea版本查询:菜单栏 > Help > About
)
4)File > Settings > Plugins > 齿轮图标 > Install Plugin from Disk...
5)导入下载的jar包,重启idea
6)File > Settings > Other Settings > Save Action > 勾选如下选项
2.2.2、效果
同在线安装