An overview,
There is no doubt that IntelliJ IDEA has become the most useful development tool for Java development. This article mainly records some common configurations in the process of using IDEA development, mainly according to their own development habits. The purpose of recording this article is to facilitate their own query configuration. And hope to read this article partners to provide some reference.
Note: THE IDEA version I use here is IntelliJ IDEA 2021.1.1 (Ultimate Edition). The configuration varies depending on the version you use. You can modify the configuration based on the version you use.
2. Common configuration of IDEA
Here does not introduce idea download or activation method, baidu you know. Here, the principle of setting IDEA is to keep the default Settings as far as possible. Except for the Settings I need, all other Settings will be kept default. Personally, I think IDEA is just a development tool.
1. Set the theme color of IDEA
Go to File –> Settings –> Appearance –> Theme. If you prefer a white Theme color, you can choose a Theme color according to your preference, as shown below:
2. Set the font size and character encoding
- Set font size
Go to File –> Settings –> Editor –> Font Font size and set it based on your PC’s screen. I’ve set it to 18.
- Setting the file encoding
Go to File –> Settings –> Editor –> File Encodings
From the figure above, you can see that there are four places to configure the encoding:
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 options are used to configure the encoding of the files in the project, excluding the properties configuration file. These three options have priority. The higher priority overrides the lower priority, that is, if the file has a specified encoding, use the specified encoding, if not, use the parent directory or project encoding. You can see in File/Directory Encoding that the root Directory of the entire project is configured to be UTF-8. File/Directory Encoding: UTF-8 Another is the separate configuration of the properties file, which follows the system by default.
Transparent native-to-ASCII conversion Whether the option is selected is shown in the following figure:
The idea of official documentation address: www.jetbrains.com/help/idea/e…
Transparent native-to-ASCII conversion Transparent native-to-ASCII conversion Transparent native-to-ASCII conversion The default encoding of the properties file of idea project follows the system, which is GBK under Windows. However, when Java program reads the properties file, it reads it in UTF-8 format, which is incompatible with the encoding and presents garbled characters. So change the properties file to utF-8 encoding to solve the problem. Another solution is to use the native-to-ASCII function to convert the input characters to code points in the UNICO code table, or UNICO values, such as \ U0041 for the letter A. These UNICO values are all characters in the ASCII code table. Because the ASCII character encoding is compatible with GBK and UNICO, Java programs can read these UNICO values correctly even if the properties file is GBK encoded. 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, so as to solve the coding compatibility problem.
Generally we need to set the file encoding to UTF-8 and check the checkbox, or the file encoding to ISO-8859-1 is also ok.
3. Set a custom comment template
Define class annotation templates
Go to File –> Settings –> Editor –> File and Code Templates to see what the following image looks like:Image belowFile Header
That corresponds to the figure above#parse("File Header.java")
By default, there is no content. Here is the custom template content:The content of a custom template is as follows:
/**
* ${describe}
*
* @name ${NAME}
* @author ${USER}
* @date ${YEAR}-${MONTH}-${DAY} ${TIME}
*/
Copy the code
After the above template is saved, creating a new Java file will display the comment information in the header of the file, as shown below:
Here,@name
和 @date
If idea is marked yellow, the warning information is displayedWrong tag
That is, IDEA cannot recognize this tag. For developers with obsessive-compulsive disorder, this prompt tag cannot be tolerated. How to eliminate this tag? You can click on it as promptedAdd date to custom tags
Idea adds this custom tag to the Java Doc custom tag. We have custom tags that can also be added here, separated by commas, as shown below:
Define method comment templates
Go to File –> Settings –> Editor –> Live Templates idea there are lots of shortcuts by default. For example, if you type sout in your program, it will actually print system.out.println (), Using these shortcuts can greatly improve our development efficiency. For specific use, you can view the specific implementation of shortcuts, as shown in the figure below:
The content of the Template text is as follows:
**
*
* @author $user$
* @date $date$ $time$
$params$
* @return $return$
*/
Copy the code
The applicable scope of method annotation template is Java as shown below:
The variables in the template are defined as follows:
The contents of the Groovy script for the params variable look like this:
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())Copy the code
After following the above steps, you can enter the add keyword on the method, and the prompt will appear. The result is as follows:The generated method annotation looks like this:
4. Install common plug-ins for IDEA
Idea commonly used plug-in description:
- GenerateAllSetter: Generate getter/setter with one click (select created object -> Alt + Enter -> Generate all setter with no default value).
- GenerateSerialVersionUID: One-click generation of serialized IDS
- JRebel: Hot deployment
- Lombok: Very rich annotations that simplify getters/setters.
- POJO to JSON: Copy the entity class to JSON format with one click (right-click the entity class -> POJO to JSON).
- Easy Code: Code generation plug-in based on IntelliJ IDEA, support to customize any template (Java, HTML, JS, XML), as long as the database is related to the code can be generated by custom templates. Support database type and Java type mapping configuration, support at the same time to generate multiple table code, each table has independent configuration information, complete personalized definition, rules set by you.
- Kubernetes: k8S plug-in, when writing yamL files when checking and prompting, very convenient.
Third, summary
The above briefly records some common configurations of IDEA. The records here are not complete. If you find any configurations or plug-ins that can improve the development efficiency, please leave a comment and add them.