Home >Java >javaTutorial >How to integrate lombok.jar in Springboot
Introduction
Spring Boot is a very efficient development framework. Lombok is a set of code template solutions that will greatly improve the efficiency of development. It is introduced here for everyone to use.
What Lombok wants to solve is the large number of Getter/Setter methods in our entity beans, as well as toString, hashCode, etc. that may not be used, but sometimes still need to be overridden for convenience; After using Lombok, it will automatically help you generate code. Note that it is automatically generated for you during the running process. That is to say, the total amount of your code will be greatly reduced.
First add the lombok.jar dependency to the pom.xml file of the project. You only need to fill in the groupid and artifactid. The version and scope have been defined in the parent project boot project
<dependency> <groupid>org.projectlombok</groupid> <artifactid>lombok</artifactid> </dependency>
Then go Download lombok.jar. The purpose of downloading is to install lombok into the ide and run it in cmd.
I ran it directly in the download directory of lombok. You can also run it directly in other directories. You need to execute the command: java -jar lombok.jar download directory lombok.jar
Then your IDE installation interface will pop up. If you have multiple IDEs, you will have multiple options to choose the IDE version you are using. Note that this is the installation method of eclipse, ldea does not seem to be able to.
Finally go to the installation directory of your IDE to view the ini file. If there is the line of code -javaagent:lombok.jar, it means that the installation has been successful
Introduction to common annotations
@Getter / @Setter: can be applied to classes and properties. If placed on a class, all non-static properties will be generated. The Getter/Setter method, placed on the property, will generate the Getter/Setter method for the property. And you can specify the access level of Getter/Setter methods.
@EqualsAndHashCode: By default, all non-transient and non-static fields will be used to generate equals and hascode methods. You can also specify specific Which properties to use. @ToString generates the toString method. By default, the class name and all attributes will be output. The attributes will be output in order and separated by commas.
@NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructor:No-parameter constructor, partial-parameter constructor, full-parameter constructor
@Data: It contains a combination of @ToString, @EqualsAndHashCode, @Getter for all properties, @Setter for all non-final properties and @RequiredArgsConstructor. Under normal circumstances, basically using this annotation is enough.
@Budilder: Can be initialized in Builder mode.
@Slf4j: Equivalent to: private final Logger logger = LoggerFactory.getLogger(XXX.class); It couldn’t be more exciting! Generally used on other java classes
The above is the detailed content of How to integrate lombok.jar in Springboot. For more information, please follow other related articles on the PHP Chinese website!