IDEA 使用技巧--设置篇
在IDEA中通过”快捷键+TAB”实现代码自动补全。
比如System.out.println(“”);,在IDEA中可以sout + TAB实现。
常用代码自动补全快捷键
快捷键 | 说明 |
---|---|
sout | System.out.println(“”); |
psvm | main方法 |
代码生成常用的快捷键
使用psvm快捷键生成main方法
使用sout快捷键生成输出语句
使用fori快捷键生成普通for循环
增强for循环的快捷键生成,使用 集合.for的快捷键方式生成
使用ctrl + alt + t快捷键,可以生成流程控制语句。
使用alt+insert快捷键,可以生成构造方法、get和set方法、重写toString()的方法、重写父类的方法等。
构造方法生成
生成get和set方法
生成toString的方法
重写父类的方法
14. Debug调试模式使用
正常编写代码,需要调试的时候,可以在指定的位置加上断点(鼠标左键点击一下即可)
使用debug方式运行main主函数
掌握debug调试模式下的快捷键
单步执行
让程序走下去
让断点进入调用的方法内
返回上一级调用
class SimpleCalc {
public int value;
public void calculate() {
value += 7;
}
}
public class MultiCalc extends SimpleCalc {
public void calculate() {
value -= 3;
}
public void calculate(int multiplier) {
calculate();
super.calculate();
value *= multiplier;
}
public static void main(String[] args) {
MultiCalc calculator = new MultiCalc();
calculator.calculate(2);
System.out.println("Value is: " + calculator.value);
}
}
编写自己的live templates
1.打开Live Templates,点击+新建live template或live template分组,我这里新建了一个名为tag的live template在名为My Live Template的分组里。
2.IDEA提供了相关表达式可以实现某些操作,点击Edit variables编辑模板变量,在Expression中调用相关表达式。
比如,我在模板中定义了一个NAME模板变量($NAME$
),点击Edit variables就可以看到这个变量,在Expression中调用了className()返回当前类的类名。
live templates表达式参考文档地址:https://www.jetbrains.com/idea/help/creating-and-editing-template-variables.html
生成serialVersionUID:
默认情况下Intellij IDEA关闭了继承了Java.io.Serializable的类生成serialVersionUID的警告,如果需要提示生成serialVersionUID,那么需要做以下设置:在Editor->Inspections下勾选中Java->Serialization issues->Serializable class without ‘serialVersionUID’,将光标放到类名上按Atl+Enter键就会提示生成serialVersionUID了在方法名称、类名、字段名上按Alt + M,会自动加上注解模板内容
类代码模板自定义(注释)
编辑代码的时候一些模板不尽人意,设置一下类生成模板
File -- Settings -- Editor -- Code Style -- File and Code Templates
主要是修改了注释
/**
*@Description:${DESCRIPTION}
* @author:
* @create: ${YEAR}-${MONTH}-${DAY} ${TIME}
**/
1、文件修改变动:
svn文件修改后,默认只有当前文件更改而父文件没有标注,很不直观;查了一顿后,发现,可以设置;
File—->settings—->version control—–>勾选show directories with changed descendants
2、IDEA以新窗口的形式打开多个项目
3、解决tomcat中文乱码问题
JAVA_TOOL_OPTIONS -Dfile.encoding=UTF-8
4、同时引入多个文件方法时,文件路径会转换成*号
Setting--editor--code sytle--java--imports
把Class count to...和Names count to...后边的数值调大一点。
5、IDEA编译特别慢。
修改:
File--Settings-Compiler的Addtional build process VM options
如下配置:
-ea -Xms2048m -Xmx2048m
6、IDEA统一编辑文件编码
全局编码设置
File -> Other Settings -> Default Settings
Editor -> File Encodings
7、当idea中properties配置文件中文显示utf8编码乱码
file->setting->editor->file encodings
把transparent native-to-ascll conversion勾选上就行了。
8、解决IDEA中tomcat启动控制台乱码问题。
菜单栏run- Edit Configurations 或 右上角有个向下的小箭头
选择你乱码的tomcat -> service->VM option,配置虚拟机编码格式为UTF-8(-Dfile.encoding=UTF-8)
9、Intellij idea用快捷键自动生成序列化id
Intellij idea用快捷键自动生成序列化id
类继承了Serializable接口之后,使用alt+enter快捷键自动创建序列化id
进入setting→inspections→serialization issues→选择图中的选项。serializable class without ‘serialVersionUID’
10、配置SVN
11、配置Maven
12、配置tomcat容器
13、全局编译时忽略某个目录或文件不进行编译。
14、设置统一编译器和编译版本
推荐使用Javac编译器
15、设置类注释文件
/**
* @Package ${PACKAGE_NAME}
* @author 侯文远
* @date ${DATE} ${TIME}
* @version V1.0
* @Copyright © 2016-2017 奥琦玮信息科技(北京)有限公司
*/
16、设置方法注释
先创建一个自定义快捷键,输入如下内容:(第一行不要加*号,因为你在已生成列表里是有的时候他前面已经存在一个*号了。)
@author 侯文远
* @date $date$ $time$
使用步奏:
1)在方法的上部输入/**+enter
2)填入相关信息
3)在最尾部输入自定义快捷键,我的是@aut+tab
效果图:
17、IDEA忽略某个文件或者文件夹,如系统的.idea文件夹和.iml文件。
18、Language Injection正则或JSON校验。
在字符串的赋值处,Alt+Enter选择Inject Language or reference
19、给选中内容添加双引号“”或单引号''
Settings - Editor - General - Smart Keys - 选中 Surround selection on typing quote or brace
使用方法:
选中要添加双引号的代码 然后按键盘上的双引号(shift+")即可
扩展:
设置之后也可以直接在选中内容两边加上《》,[],{}等,使用方法类似。选中代码之后,点<、{、[