4
头图

I. Overview

There is no doubt that IntelliJ IDEA has become the best development tool for Java development. This article mainly records some common configurations in the development process of using idea. It is mainly configured according to own development habits. The purpose of recording this article is to It is convenient to query the configuration by yourself, and I hope to provide some reference to the friends who read this article.

Note: The version of idea I used here is IntelliJ IDEA 2021.1.1 (Ultimate Edition). The configuration of different versions is slightly different, and you can change it according to the specific version you use.

Two, idea common configuration

The method of downloading or activating idea will not be introduced here, you will know when you click on Baidu. The principle of setting idea here is to keep the default settings as much as possible, except for the settings you need, all other settings are kept by default. I personally think that idea is just a development tool, how to use it and how to set it, but to improve your own development efficiency.

1. Set the theme color of idea

Click File --> Settings --> Appearance --> Theme
Personally like the white theme color, you can choose the corresponding theme color according to your own preferences, as shown in the figure below:

2. Set the font size and character encoding

  • Set font size

Click File --> Settings --> Editor --> Font
The font size is set according to the screen of the personal computer, the size I set here is: 18.

  • Set file encoding

Click File --> Settings --> Editor --> File Encodings

From the figure above, you can see that there are 4 places to configure the code:

1、Global Encoding:UTF-8
2、Project Encoding: UTF-8
3、File/Directory Encoding: UTF-8
4、Properties files Encoding:UTF-8

The first three are the encoding of the file in the configuration project, excluding the properties configuration file. These three options have priority. The high priority overrides the low priority, which means that if the file has a specified encoding, the specified encoding will be used. If not specified, the encoding of the parent directory or project is used.
You can see that the root directory of the entire project is configured as UTF-8 in File/Directory Encoding.
Generally, we don't care about these three configurations. Idea will automatically configure File/Directory Encoding: UTF-8.
The other is the separate configuration of the properties file, which follows the system by default.

Transparent native-to-ascii conversion This option is checked or not, the official document explains as follows:

Idea official document description address: https://www.jetbrains.com/help/idea/encoding.html#file-encoding-settings

Transparent native-to-ascii conversion directly translated to transparently convert the local code to ascii code. From the official document, it seems that I don’t understand it. Check some information and explain it as follows:
The encoding of the properties file of the idea project follows the system by default. It is gbk under windows, but when the java program reads the properties, it is read in UTF-8 format. The encoding is incompatible and appears garbled, so change the properties file to UTF-8 encoding to solve the problem. problem. Another solution is to use the native-to-ascii function to convert the input characters into code points in the unico code table, or unico values, for example, \u0041 represents the English letter a. These unico values are all characters in the ascii code table, because the character encoding of the ascii part is compatible in gbk and unico, so even if the properties file is gbk-encoded, the java program can correctly read these unico values, and Find the corresponding character. The simplest way to understand: Chinese characters are converted into unico code points and stored in gbk-encoded files. Java then finds the corresponding Chinese characters through these code points to solve the encoding compatibility problem.

Generally, we need to set the file encoding to UTF-8 and check the check box at the same time, or it is also possible to set the file encoding to ISO-8859-1.

3. Set up a custom annotation template

Define class annotation template

Click File --> Settings --> Editor --> File and Code Templates
Select Class to view as shown in the figure below:

File Header in the #parse("File Header.java") figure above. There is no content by default. The following figure is a custom template content:

The content of the custom template is as follows:

/**
 * ${describe}
 * 
 * @name ${NAME}
 * @author ${USER}
 * @date ${YEAR}-${MONTH}-${DAY} ${TIME}
 */

After the above template is saved, create a new Java file, and the comment information will be displayed in the header of the file, as shown in the following figure:
输入描述信息
生成模板注释

Here @name and @date are marked as yellow by idea, and the warning message is Wrong tag , which means that idea cannot recognize this tag. For developers with obsessive-compulsive disorder, this kind of prompt mark cannot be tolerated. How to eliminate this mark? Add date to custom tags according to the prompt, and then the yellow mark is gone. Idea adds this custom label to the custom label of Java doc. We have custom labels that can also be added here, separated by commas, as shown below Shown:

Define method comment template

Click File --> Settings --> Editor --> Live Templates
Idea provides a lot of shortcuts by default. For example, if you enter sout in the program, it will actually output System.out.println() . Using these shortcuts can greatly improve our development efficiency. For specific use, you can view the specific implementation of the shortcuts, as shown in the following figure Show:

定义方法注释模板

Next, we will introduce the annotation template of the custom method
The template content Template text is as follows:

**
 * 
 * @author $user$
 * @date $date$ $time$
 $params$ 
 * @return $return$
 */

自定义方法注释模板
The applicable range of method annotation template is Java, as shown in the following figure:

The variable definition in the template is shown in the figure below:
模板中的变量定义

The content of the groovy script of the params

groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {if(i == 0) result += '* @param ' + params[i] + ' ' + ((i < params.size() - 1) ? '\\n' : '');else result += ' * @param ' + params[i] + ' ' + ((i < params.size() - 1) ? '\\n' : '')}; return result", methodParameters()) 

After completing the configuration according to the above steps, you can enter the add keyword in the method, and a prompt will appear, and the effect is as follows:
在方法上面输入 /add
The effect of the generated method annotation is as follows:

生成方法注释

4. Idea install common plug-ins

Idea common plugin description:

  • GenerateAllSetter : Generate getter/setter with one click (select the created object -> alt + enter -> Generate all setter with no default value).
  • GenerateSerialVersionUID : Generate serialization ID with one click
  • JRebel : hot deployment
  • Lombok : Provide very rich annotations to simplify getter/setter.
  • POJO to JSON : One-click copy entity class to Json format (right click on entity class -> POJO to Json).
  • Easy code : A code generation plug-in developed based on IntelliJ IDEA, supports customizing any template (Java, html, js, xml), as long as it is database-related code can be generated through a custom template. Support database type and java type mapping relationship configuration, support to generate code to generate multiple tables at the same time, each table has independent configuration information, completely personalized definition, and the rules are set by you.
  • Kubernetes : k8s plug-in, there are checks and prompts when writing yaml files, which is very convenient.

Three, summary

The above briefly records some common configurations about idea. The records here are not complete. If you find any configuration or plug-ins that can improve development efficiency, please leave a message to add.


惜鸟
328 声望2.3k 粉丝