This is the 12th day of my participation in the August More Text Challenge. For details, see:August is more challenging

Include a column

Spring Boot quick start

Java full stack Architect

preface

I believe that most developers have encountered a large number of property generation constructors, getters/setters, equals, hashcode, toString methods in Java objects, which is very lengthy and not too much technical content. Once you change the property, it is easy to forget to change the corresponding method. So is there a good way to simplify this redundant and inefficient code? Now let’s introduce Lombok to you.

The initial

Lombok is a Java utility that helps developers eliminate the verbosity of Java, especially for simple Java objects (POJOs). It does this through annotations. By implementing Lombok in a development environment, developers can save much of the time spent building methods such as hashCode() and equals() and sorting various accessors and mutators.

Lombok shortcomings

  • Eliminate redundant, inefficient code
  • Annotations enable rapid development

Lombok shortcomings

  • Forced installation, if one person on the team uses the Lombok plug-in, everyone must install it.
  • Code readability, low debuggability, lack of responsive methods in the development process, only generated in the compile phase.
  • There are unknown risks: developers become overly dependent on it, with unintended consequences.
  • Impact upgrades: very intrusive to code, upgrades to JDK and framework,
  • Breakage of encapsulation, code coupling increased, a certain degree of interference to the project.

Lombok annotations

annotations describe
@NonNull Nonempty parameter checks before methods or constructors
@Cleanup Automatic resource management, safe call to the close method
@Getter Member variables generate the corresponding set method
@Setter Member variables generate the corresponding GET method
@ToString Generate toString, equals, and HashCode methods
@EqualsAndHashCode Generate toString, equals, HashCode, and canEqual methods
@NoArgsConstructor Produces a parameterless constructor for a class
@RequiredArgsConstructor All member variables ina class with @nonnull annotation or final decoration generate the corresponding constructor
@AllArgsConstructor Generates a constructor that contains all parameters for the class
@Data Note on the class, provide the class get, set, equals, hashCode, canEqual, toString methods
@Value Similar to @data, it is defined as private final and does not generate a set method
@SneakyThrows Catch an exception and throw it in a catch using Lombok. SneakyThrow (e)
@Synchronized Same as the synchronized keyword
@Log Annotations are used on classes to log directly

Lombok installation

Set up the

Select the file directory and click Settings.Select Plugins and search for Lombok.Select install.

Add the dependent

<! -- lombok start --><dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
            <scope>provided</scope>
        </dependency><! -- lombok end -->Copy the code

More quick start reference: [Rapid Development] Lombok Quick Start

conclusion

Lombok’s integration with Spring Boot is successful. More tests you can delve into Lombok related information, I believe there will be new discoveries.

Author introduction: [little ajie] a love to tinker with the program ape, JAVA developers and enthusiasts. Public account [Java full stack architect] maintainer, welcome to pay attention to reading communication.

Well, thank you for reading, I hope you like it, if it is helpful to you, welcome to like the collection. If there are any shortcomings, please comment and correct them. See you next time.

Recommended Reading:

My first Spring Boot project is up!

Spring Boot column was set up over the weekend. Welcome to learn and communicate

Spring Boot integrates MyBatis and connects to the database.

【Spring Boot Quick Start 】 four, Spring Boot integration JUnit

【Spring Boot Quick Start 】 5, Spring Boot integrated Swagger UI