Application of Lombok in springboot project


Background analysis

In actual Java projects, almost all the POJO classes we create need to add set / get / toString and other related methods for attributes. All logging related classes may need to create objects such as logs. These template codes have no technical content and affect the beauty of the code. At the same time, the repeated coding process will increase our workload. At this time, we have Lombok.

About Lombok

Lombok is a third-party Java library, which will be automatically inserted into the editor and build tool. Lombok provides a set of useful annotations to tell the compiler in the compilation process to add some sample code to the bytecode in the process of compiling the source code into bytecode.
Common notes:
@Setter: used to generate setter methods for the described classes, and does not contain final decorated properties
@Getter: used to generate getter methods for described classes
@ToString: used to add a toString method to the described class
@Equalsandhashcode: a parameterless construction method for class generation
@The class described by date generates setter / getter / equals / canequal / hashcode / toString methods. If it is a final property, the property will not generate setter methods
@Slf4j: add a log property object to the description class

Lombok use

1. Installing Lombok plug-in in idea
2. Add dependency
3. Setting > build, exception, deployment > annotation processors – check enable annotation processing