Introduction: IDEA is a tool for code development. Comfortable settings and correct coding posture can make typing code more swift and smooth, and get twice the result with half the effort! This document also contains some solutions to the problems, welcome to read!
Note: IDEA version 2021.2.1. For different versions of IDEA, the set names may be different, but they are almost the same.
write in front
IDEA settings are divided into spaces. There are single projects and global settings. A single project will only take effect on the current project, and the global will take effect on the new project (some settings will only take effect on a single project, such as maven. It is recommended to set all settings globally . settings )
- For a single item, click directly
File -> Settings...
- Globally, if you click on an open project
File -> Close Project
and close all projects, you will jump to a window like the one below (this is also the page if no projects are open)
and then clickCustomize -> All settings...
1. Plug-in
Good plug-ins allow you to write code with twice the result with half the effort
-
Translation
translation function, translation shortcut key Ctrl+Shift+Y.
This plug-in is currently not easy to use due to the inaccessibility of the Google Translate interface. However, you can configure the translation interface yourself. You can register a Baidu translation interface. There should be free requests. frequency -
The lombok
entity class enhancement plug-in allows you to create common methods for entity classes through comments.
Currently, IDEA should be installed by default. -
CodeGlance
code thumbnail display.
Versions 2, 3, and Pro are all similar. I use Pro. -
MybatisX
can generate code and quickly find the corresponding method in xml from the Mapper class. -
Rainbow Brackets
can add colors to different levels of brackets to avoid confusion -
Easy Code
code generation plug-in can generate Controller, Service, Entity, Mapper, etc., is compatible with MybatisPlus, and can also remove prefixes. Class annotation author name, sql-java type matching, template, etc. can be configured by yourselfFile -> Settings... -> Other Settings -> Easy Code
in
2. Modify font (YaHei Consolas Hybrid)
The most commonly used font is the consolas font, but I also feel that the default Song font is ugly, so I use the Microsoft Yahei version of the consolas font.
Settings -> Editor -> Font
, Font selection: YaHei Consolas Hybrid
font resource download: https://pan.baidu.com/s/1YATb_ObjCuARE1VUvjNqhg
extraction code: fnee
3. Shortcut keys
-
Redo
I used to use Ctrl+ Yto undo code modifications
Settings -> Keymap -> Main Menu -> Edit -> Redo
: right-click Add Keyboard Shortcut -
Basic
This is the code association prompt function. I was used to Alt+ /,
Settings -> Keymap -> Main Menu -> Code -> Code Completion -> Basic
:right click Add Keyboard Shortcut
Note: The modified shortcut keys may conflict. IDEA will prompt a pop-up window, just remove it.
4. Modify maven
Found Settings -> Build,Execution,Deployment -> Build Tools -> Maven
(in fact, searching maven directly can find it faster)
- Maven home directory :D:\apache-maven-3.6.3-bin(maven directory)
- User settings file : D:\apache-maven-3.6.3-bin\conf\settings.xml (maven configuration file)
- Local repository:D:\maven_repository(maven本地库)
5. Modify character encoding Encoding
Settings -> Editor -> File Encodings
(After adding Chinese comments in yml, the error problem will be solved)- Global Encoding:UTF-8
- Project Encoding:UTF-8
- Default encoding for properties files:UTF-8
Help -> Edit Custom VM Options...
, add-Dfile.encoding=UTF-8
(solve Chinese garbled log of tomcat in IDEA)
6. Modify JDK
File -> Project Structure -> Platform Settgings -> SDKs
, click the plus sign, find your own jdk folder and add it (add jdk)File -> Other Settings -> Structure for New Projects... -> Project Settings -> Project
, modify Project SDK to your own jdk (modify the default jdk)
7. Automatically import packages
Settings -> Editor -> General -> Auto Import
,勾选Add unambiguous imports on the fly和Optimize imports on the fly (for current project)
- Check the first option and IDEA will automatically help us import the packages we need. But for those packages with the same name, you still need to manually Alt + Enter to import them.
- Check the second option and IDEA will automatically help us optimize the imported packages, such as automatically removing some unused packages.
If you want to limit the merging of packages , open it Settings -> Editor -> Code Style -> Java
and set the Class count to use import with '*' and Names count to use static import with '*' values to be larger, for example, set them to 99
8. Remove color blocks in mapper
Settings -> Editor -> Inspection
Find No data sources configured and SQL dialect detection under SQL and uncheck them.
Settings -> Editor -> Scheme color -> General
Find the Injected language fragment under Code and select it. Set the settings on the right to uncheck Background.
9. Add spacer lines between methods
Settings -> Editor -> General -> Appearance
Check Show method separators
10. Custom mapper template
Settings -> Editor -> File and Code Templates
Click the plus sign, fill in mapper for Name , and fill in xml for Extension . The file content is as follows
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="">
</mapper>
11. Custom method annotations
Settings -> Editor -> Live Templates
, click the plus sign to add the group Template Group , I named it myDefine, and then click the plus sign Live Template to add the template
Abbreviation custom keywords, I fill in # here, description is a description of the template, I fill in "custom method comments", and then add the following content to the Template text
**
* @description
* @author 作者
* @date $date$ $time$
**/
Click Edit variables to set parameters
Click OK, Expand with selected Enter
There is a prompt for No applicable contexts at the bottom. Click Define, select Java, and click OK.
Instructions for use: Enter /# before the method and press Enter to automatically add custom comments.
12. Custom class annotations
Settings -> Editor -> File and Code Templates
, add the following content to the Class, Interface and Enum class names
/**
* @author 作者
* @since ${DATE} ${TIME}
**/
In this way, class annotations will be automatically added when creating a new java class.
13. Error reported in sql tag in mapper: <statement> or DELIMITER expected, got 'approve_id'
sql|
As shown below, just delete the Local name.
14. Solving SpringBoot hot start failure
File -> Settings... -> Build,Exception,Deployment -> Compiler
, check Build project automatically- Alt+ Ctrl+ Shift+ A+ /, select Registry, check compiler.automake.allow.when.app.running
15. Error is reported after starting with Chinese comments in yml
First remove the code with comments, then modify the following configuration, and then add the code back to solve the problem
16. unable to resolve column …
This error is very annoying, and it directly causes a large area of red in the mapper. Many solutions on the Internet are to configure the data source (almost exactly the same, no, it is written by that person), but I just don’t want to configure it (stubborn), here is mine Solution (uncheck Unresolved reference )
17. Add background image
File -> Settings... -> Appearance & Behavior -> Appearance
, there is a button: Background Image... , after clicking, the following interface will appear
- Image, image address, click on the back... to select the image
- Opacity, transparency
- This project only, as literally means, only the current project takes effect
- The next few boxes
- The first two are horizontal flips and the second are vertical flips.
- The larger one, keep the original size of the picture displayed
- The big second one, fills the entire editor
- The third largest one is displayed repeatedly (it can only be seen when the image size is smaller than the editor size)
- The last one is the alignment, as shown in the nine-square grid, the picture is top, bottom, left, right, center, top left, top right, bottom left, bottom right
- The bottom is the preview effect, one is a preview of the open file with code, and the other is a preview without opening any files.