These 12 idea plug-ins can make your code fly

foreword

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 with you about the plug-ins ideathat can improve coding efficiency 12, and I hope it will be helpful to you.

1. 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:

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.

2. Free Mybatis plugin

mybatisIt has become the most mainstream database framework in China . 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 Free Mybatis pluginplug-ins.

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.

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.

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

3.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: Translationplug-ins, which allow us to fly freely in the document.

After installing Translationthe plugin, there is a Translation menu in other settings.

Click on this menu:

In the right window, you can choose translation software.

Select the English document that needs to be translated:

In the window that pops up by right-clicking, select the Translation option, and

the following window will pop up: an English paragraph is translated into Chinese at once, which is really cool.

4.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 Alibaba Java Coding Guidelinesa plug-in, which can directly detect non-standard codes through the plug-in.

After installing the plug-in, press the shortcut key: Ctrl+Alt+Shift+Jto scan the entire project or a single file.


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

There are currently three levels shown below:

  • Blocker crashes
  • Critical
  • Major important


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。

5. GenerateAllSetter

Many times, we need to assign a value to an object. If there are many parameters, we need to write a lot of code setteror gettercode.

Is there a way to do it with one click?

A: Yes, using GenerateAllSettera plugin.

After installing the plug-in, on the created object, press the shortcut key: alt + enter.

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

The following code will be automatically generated:

it is simply too convenient.

6. SequenceDiagram

When we usually read the source code, in order to sort out the internal logic, we often need to draw some 时序图.

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: SequenceDiagramplug-in.


Select a specific method, right-click to select: sequence diagram option:

After that, a sequence diagram will appear:

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

7. 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?

A: Use CheckStyle-IDEAa plugin.

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


After installing the plugin, it will appear below the idea: CheckStyle option:

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:

8.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 JRebel and XRebela plugin.

As shown in the picture:

After the installation is complete, there will be two green buttons, and there is an option Select Rebel Agents on the right: one of the

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

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

  • JRebel: After modifying the code, do not restart the service, and expect the code to take effect directly.
  • 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.
  • JRebel+XRebel: After modifying the code, do not restart the service, and monitor the code.

9. Codota

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

But if you have used Codotaplugins, it will make your code writing speed to a new level.

After installing the plug-in, when we write code, it will give you some hints:

these hints are based on ai statistics, which are very valuable for reference.

10. GsonFormat

Many times, I need to jsonconvert the parameters in to 实体对象parameters in . Or 实体对象convert the parameters in to jsonthe parameters in .

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

But now the good news is that the idea GsonFormatplug-in can help us do 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 just cool.

11. 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 Rainbow Bracketsa plugin.


After the plug-in is installed, the brackets and back brackets will be automatically distinguished in different colors in the code:

very conspicuous and intuitive.

12. 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?

Answer: Yes, plug-ins are available CodeGlance.

After installing the plug-in, the following window will appear on the right side of the code:

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

Guess you like

Origin blog.csdn.net/lisu061714112/article/details/126659113