Home >Java >javaTutorial >12 idea plug-ins to improve your coding efficiency
This article will talk to you about the 12
plug-ins that can improve coding efficiency in idea
. I hope it will be helpful to everyone.
There was still controversy about lombok before, whether it should be used in the project, so I still I wrote a special article "Confused, should we use lombok?" 》.
Now the new version of idea has built-in lombok plug-in, so using it is a trend.
The reason why I put lombok as the first introduction in the entire article is because it can really help me write a lot less code, especially in entities, DTOs, VOs, and BOs.
We use the User class as an example. Previously, to define a javabean, you needed to write the following code:
public class User { private Long id; private String name; private Integer age; private String address; public User() { } public User(Long id, String name, Integer age, String address) { this.id = id; this.name = name; this.age = age; this.address = address; } public Long getId() { return id; } public String getName() { return name; } public Integer getAge() { return age; } public String getAddress() { return address; } public void setId(Long id) { this.id = id; } public void setName(String name) { this.name = name; } public void setAge(Integer age) { this.age = age; } public void setAddress(String address) { this.address = address; } @Override public boolean equals(Object o) { if (this == o) returntrue; if (o == null || getClass() != o.getClass()) returnfalse; User user = (User) o; return Objects.equals(id, user.id) && Objects.equals(name, user.name) && Objects.equals(age, user.age) && Objects.equals(address, user.address); } @Override public int hashCode() { return Objects.hash(id, name, age, address); } @Override public String toString() { return"User{" + "id=" + id + ", name='" + name + '\'' + ", age=" + age + ", address='" + address + '\'' + '}'; } }
The User class includes: member variables, getter/setter methods, constructor methods, equals, and hashCode methods.
At first glance, there are quite a lot of codes. And there is another question. If the code in the User class is modified, for example: the age field is changed to a string type, or the name field name is modified, does it need to modify the related member variables, getter/setter methods, constructors, etc. simultaneously? Modify all equals and hashCode methods?
The good news is that using lombok can solve this problem.
If it is a version before idea2020.3, you need to install the following plug-in in idea:
But after idea2020.3, idea has built-in lombok function.
With the lombok plug-in, now we can achieve the above functions by writing code like this in idea:
@ToString @EqualsAndHashCode @NoArgsConstructor @AllArgsConstructor @Getter @Setter public class User { private Long id; private String name; private Integer age; private String address; }
It’s so easy, and you can really write a lot less code.
In addition, we also need to introduce lombok's dependency package in the project's pom file, otherwise the project will not run.
In Chinamybatis
has become the most mainstream database framework, which is semi-automated The ORM persistence framework is more flexible and has higher performance than a fully automated persistence framework like hibernate.
In mybatis
, we need to define the mapper and the corresponding xml file ourselves to complete the binding.
Here we take the user table as an example. First we need to define the UserMapper interface:
public interface UserMapper { int insertUser(UserModel user); }
Then we need the UserMapper.xml configuration file:
<?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="com.sue.jump.mappers.UserMapper"> <sql id="selectUserVo"> id, name, age, sex </sql> <insert id="insertUser" parameterType="com.sue.jump.model.UserModel"> INSERT INTO user <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null "> id, </if> <if test="name != null and name != ''"> name, </if> <if test="age != null "> age, </if> <if test="sex != null "> sex, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null "> #{id}, </if> <if test="name != null and name != ''"> #{name}, </if> <if test="age != null "> #{age}, </if> <if test="sex != null "> #{sex}, </if> </trim> </insert> </mapper>
In the UserMapper.xml file, mapper The namespace of the label corresponds to the UserMapper interface name, and the id of the insert label=insertUser, which corresponds to the insertUser method in the UserMapper interface.
So, how can we quickly access the getUser method in the UserMapper.xml file through the getUser method in the UserMapper class in the project?
Answer: This requires the use of the Free Mybatis plugin
plugin.
After installing the plug-in, there will be two more green arrows to the left of the interface name and method name of the UserMapper interface. Click on the arrow to jump. Go to the mapper tag or insertUser statement corresponding to the UserMapper.xml file.
In addition, there will be an extra green arrow on the left side of the insertUser statement in the UserMapper.xml file. We can also jump to the UserMapper interface by clicking on the arrow. on the insertUser method.
With this plug-in, we can freely switch between mapper and xml, play freely, and no longer have to search like before.
Some friends, including myself, may not be very good at English (I have just passed CET-4).
When we name variables or methods, we have to think about it for a long time. Especially when reading the JDK English documentation, I encountered some uncommon words, which was really confusing.
The good news is that using: Translation
plug-in allows us to fly freely in the document.
After installing the Translation
plug-in, there is an additional Translation menu in other settings.
Click on this menu:
In the window on the right, you can choose the translation software.
Select the English document that needs to be translated:
In the right-click pop-up window, select the Translation option, and the following window will pop up:
An English paragraph was suddenly translated into Chinese. It was so cool.
If you are a friend engaged in Java development, you must have read Alibaba's "Java Development Manual".
This manual summarizes the problems we may encounter in our daily development process. From programming protocols, exception logs, unit tests, security protocols, MySQL database and project structure, these six aspects standardize the development process and ensure that we can write efficient and elegant code.
But these normative things, relying solely on people’s consciousness, are difficult to achieve the expected results.
In order to solve this problem, Alibaba launched the Alibaba Java Coding Guidelines
plug-in, which can directly detect non-standard code.
After installing the plug-in, press the shortcut key: Ctrl Alt Shift J
to scan the entire project or a single file for coding conventions.
After scanning, the non-standard codes will be sorted from high to low.
There are currently three levels shown below:
Click on one of the irregular code lines on the left, and the detailed irregular code will be immediately displayed in the window on the right, allowing us to quickly locate the problem.
nice.
Many times, we need to assign a value to an object. If there are many parameters, we need to write a lot of setter
or getter
Code.
Is there any way to do it with one click?
Answer: Yes, use the GenerateAllSetter
plug-in.
After installing the plug-in, press the shortcut key on the created object: alt enter
.
Select in the pop-up window: Generate all setter with default value.
will automatically generate the following code:
It’s so convenient.
When we usually read the source code, in order to sort out the internal logic, we often need to draw some sequence diagrams
.
If we draw directly, it will waste a lot of time, and the picture drawn may not be correct.
You can use: SequenceDiagram
plug-in.
Select a specific method, right-click and select: sequence diagram option:
After that, the sequence diagram will appear:
From now on, I can become a master of drawing, perfect.
In terms of code format, there are many places that we need to pay attention to, such as: useless imports, no comments, grammatical errors, and too many methods. Long wait.
Is there any way to detect the above problems at once in the idea?
Answer: Use the CheckStyle-IDEA
plug-in.
CheckStyle-IDEA
is a tool to detect whether the code format meets the specifications. The most commonly used ones are the Google
specification and the Sun
specification. .
After installing the plug-in, the CheckStyle option will appear below the idea:
Click the green button on the left , you can scan the code. In the middle, the reason for noncompliance with code specifications is displayed.
Double-click the code to jump directly to the specific code:
JRebel and XRebel
plug-in.As shown in the picture:
After the installation is completed, there will be two green buttons here, and an additional option Select Rebel Agents on the right:
One of the green buttons indicates hot deployment startup project, and the other one indicates hot deployment startup project with debug default.Select Rebel Agents option contains three values:
JRebel: After modifying the code, do not restart the service, and expect the code to take effect directly.
Codota
plug-in, it will make your code writing speed go to the next level.After installing the plug-in, it will give you some tips when we write code:
These tips are based on ai The statistics are very valuable for reference.
10. GsonFormat
entity objects parameter. Or convert the parameters in
entity object into parameters in
json.
In the past, we used to manually copy one variable and one variable.
GsonFormat
plug-in can help us accomplish this.After installing the plug-in, first create an empty class:
Press the shortcut key: alt s
, the following window will pop up:Then enter the json data in this window.
Click the OK button and these codes will be automatically generated: It’s so cool.
11. Rainbow Brackets
Rainbow Brackets
plug-in.
is very conspicuous and intuitive.
12. CodeGlance
CodeGlance
plug-in.After installing the plug-in, the following window will appear on the right side of the code:
If this article is helpful or inspiring to you, please help scan and send the QR code Pay attention, your support is my biggest motivation to keep writing.
Please click three links: like, retweet, and watching.
Follow the public account: [Su San talks about technology], reply in the public account: Interviews, code artifacts, development manuals, time management have great fan benefits, and reply: Join the group, you can follow many seniors from BAT companies Communicate and learn.
(Learning video sharing: Basic Programming Video)
The above is the detailed content of 12 idea plug-ins to improve your coding efficiency. For more information, please follow other related articles on the PHP Chinese website!