Several commonly used idea plug-ins, the subject is also using

Part of the content is transferred from: Code Farmer Code Road

Basically every programmer can write code, but at different speeds.

Why some people can only write a few hundred lines of code a day?

And some people, can write thousands of lines of code a day?

Is there a way to improve development efficiency and write more code in the same time?

Today I will talk to you about 12 plug-ins that can improve coding efficiency in idea, and I hope it will be helpful to you.

lombok

There was still controversy about lombok before, whether it should be used in the project or not, so I also wrote a special article "Confused, should we use lombok?" ".

Now the new version of idea has a built-in lombok plug-in, so it is a trend to use it.

The reason why I put lombok in the first introduction of the whole article is because it can really help me write a lot less code, especially in entity, DTO, VO, and BO.

Let's use the User class as an example. In the past, defining a javabean required writing 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, construction methods, equals, hashCode methods.

At first glance, the code is still quite a lot. 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 changed, do you need to modify the related member variables, getter/setter methods, construction methods, Modify all the equals and hashCode methods?

The good news is that lombok can solve this problem.

If it is a version before idea2020.3, you need to install the following plug-ins in idea:
insert image description here

But after idea2020.3, idea has built-in lombok function.

With the lombok plug-in, now we only need to write code like this in idea to realize the above functions:

@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, you can really write a lot less code.

In addition, we also need to introduce the lombok dependency package in the pom file of the project, otherwise the project will not run.

Free Mybatis plugin

In China, mybatis has become the most mainstream database framework. This framework belongs to the semi-automatic ORM persistence framework, which is more flexible and has higher performance than the fully automated persistence framework such as hibernate.

In mybatis, we need to define the mapper and the corresponding xml file 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 the UserMapper.xml configuration file is required:

<?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, the namespace of the mapper tag corresponds to the UserMapper interface name, and the id=insertUser of the insert tag corresponds to the insertUser method in the UserMapper interface.

So, how to 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.
insert image description here

After installing the plug-in, there will be two green arrows on the left side of the interface name and method name of the UserMapper interface. Click the arrow to jump to the mapper tag or insertUser statement corresponding to the UserMapper.xml file.
insert image description here

In addition, on the left side of the insertUser statement in the UserMapper.xml file, there will also be a green arrow. Clicking this arrow can also jump to the insertUser method of the UserMapper interface.
insert image description here

With this plug-in, we can freely switch between mapper and xml, play freely, and no longer need to search and search like before.

Translation

Some friends, including myself, may not be very good at English (I 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 a big headache.

The good news is to use: Translation plug-in, which allows us to fly freely in the document.
insert image description here

After installing the Translation plug-in, there is an additional Translation menu in other settings or Tools.

Click on this menu: In the right window, you can choose translation software.
insert image description here

Select the English document to be translated:
insert image description here

In the right-click pop-up window, select the Translation option, and the following window will pop up:
insert image description here
an English paragraph is translated into Chinese at once, which is really cool.

Alibaba Java Coding Guidelines

If you are a small partner engaged in Java development, you must have read Alibaba's "Java Development Manual".

This manual summarizes the problems we may encounter in the daily development process. From programming regulations, exception logs, unit tests, security regulations, Mysql database and engineering structure, these six aspects standardize the development process and ensure that we can write efficient and elegant code.

However, it is difficult to achieve the expected effect of these normative things only relying on human consciousness.

In order to solve this problem, Alibaba launched the Alibaba Java Coding Guidelines plug-in, which can directly detect non-standard codes through this plug-in.
insert image description here

After installing the plug-in, press the shortcut key: Ctrl+Alt+Shift+J to scan the entire project or a single file for encoding regulations.

insert image description here

After scanning, irregular codes will be sorted from high to low.

There are currently three levels shown below:

  1. Blocker crashes
  2. Critical
  3. Major important

insert image description here

Click one of the non-standard code lines on the left, and the non-standard detailed code will be displayed immediately in the right window, which is convenient for us to quickly locate the problem.

nice。

GenerateAllSetter

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 codes by hand.

Is there a way to do it with one click?

Answer: Yes, use the GenerateAllSetter plugin.

picture

After installing the plugin, on the created object, press the shortcut key: alt + enter.

In the pop-up window, select: Generate all setter with default value.
insert image description here

The following code will be automatically generated:
insert image description here

It's just so convenient.

SequenceDiagram

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.

At this time you can use: SequenceDiagram plug-in.

insert image description here

Select a specific method, right click and select: sequence diagram option:
insert image description here

After that, a sequence diagram will appear:
insert image description here

From then on, I can become a master of drawing, perfect.

CheckStyle-IDEA

In terms of code format, there are many places that need our attention, such as: useless imports, unwritten comments, grammatical errors, methods that are too long, and so on.

Is there a way to detect the above problems at one time in the idea?

Answer: Use the CheckStyle-IDEA plugin.

CheckStyle-IDEA is a tool to detect whether the code format meets the specifications, among which Google specifications and Sun specifications are used more.

insert image description here

After installing the plugin, it will appear below the idea: CheckStyle option:
insert image description here

Click the green button on the left to scan the code. In the middle position, the reason for non-compliance with the code specification is displayed.

Double-click the code to jump directly to the specific code:
insert image description here

JRebel and XRebel

There is a very uncomfortable thing about developing Java projects in idea: every time you modify a class or interface, you need to restart the service, otherwise the latest place will not run.

And every restart takes a lot of time.

Is there any way, after the Java code is modified, it will take effect immediately without restarting the system?

A: Use the JRebel and XRebel plugins.

As shown in the picture:picture

After the installation is complete, there will be two green buttons, and there is an option Select Rebel Agents on the right:
insert image description here

One of the green buttons means that the hot deployment starts the project, and the other means that the default hot deployment starts the project with debug.

There are three values ​​in the Select Rebel Agents option:

  1. JRebel: After modifying the code, do not restart the service, and expect the code to take effect directly.
  2. XRebel: During the request process, the performance monitoring of each part of the code. For example: method execution time, exceptions, SQL execution time, output Log, MQ execution time, etc.
  3. JRebel+XRebel: After modifying the code, do not restart the service, and monitor the code.

Codota

To be honest, idea's existing code hinting function is already very powerful.

But if you have used the Codota plugin, it will make your code writing speed to a higher level.
insert image description here

After installing the plugin, when we write code, it will give you some hints:
insert image description here

These hints are based on AI statistics and are of great reference value.

GsonFormat

Many times, I need to convert the parameters in json into parameters in entity objects. Or convert the parameters in the entity object into parameters in json.

In the past, we used to manually copy one variable and one variable.

But now the good news is that idea's GsonFormat plugin can help us do this.

insert image description here

After installing the plugin, first create an empty class:
insert image description here

Press the shortcut key: alt + s, the following window will pop up:
insert image description here

Then in this window, enter the json data.

Click the OK button, and these codes will be automatically generated:
insert image description here

Simply stunning.

Rainbow Brackets

When we usually write code, parentheses are a very headache for us, especially when the code has a lot of logic and is nested layer by layer.

At a glance, it is difficult to see which parenthesis the code begins and which back parenthesis ends.

Is there a way around this?

A: Use the Rainbow Brackets plugin.

insert image description here

After installing the plug-in, the brackets and back brackets will be automatically distinguished according to different colors in the code:
insert image description here

Very conspicuous, very intuitive.

CodeGlance

Sometimes, we read a lot of code, for example, a class contains many methods and member variables.

Turning from top to bottom, little by little, will waste a lot of time. So is there a way to quickly flip to the code you want to see?

A: Yes, you can use the CodeGlance plug-in.
insert image description here

After installing the plugin, the following window will appear on the right side of the code:
insert image description here

It is a thumbnail of the code, through which we can switch code blocks very quickly.

Maven Helper

After installation, there will be an additional Dependcy Analyzer tab in the pom file
insert image description here

  1. Conflicts: Show conflicting dependencies
  2. All Dependencies as List: Display dependencies in a list
  3. All Dependencies as Tree: Display dependencies in the form of a tree

When encountering a conflicting dependency, you can right-click to jump to the source file or directly select Exclude to exclude this dependency

insert image description here

Leetcode Editor

After brushing algorithm questions in IDEA
, after the installation number, there will be a Leetcode Plugin menu in Tools to set it up. When writing questions, in the left sidebar of the idea interface:
insert image description here

Guess you like

Origin blog.csdn.net/qq_16607641/article/details/127230855