Guide package: Import Lombok. Data;
Lombok simplifies Java code:
In Lombok, there are altogether three annotation to generate a constructor method:
@NoArgsConstructor, @RequiredArgsConstructor, @AllArgsContructor. The
uses these three annotation to complete the requirements for different construction methods in the project.
@NoArgsConstructor: Generates a parameterless construction method that highlights the importance of this annotation when used in conjunction with other annotation,
For example, when using the Hibernate framework, If there is an argument to the construction method, Noargsconstructor will show his role.
@RequiredArgsConstructor: A construction method that contains constants, and variables that identify Notnull, is generated. The build method is private, and you can use the Staticname option to generate a static method if you want to provide it externally.
@AllArgsContructor:? Generates a check that contains all the variables, and if the variable uses notnull annotation, it will be empty.
Here are a few of the Lombok annotations I use frequently:
@Data : Annotations on classes, providing getting and setting methods for all properties of the class, plus the Equals, canequal, Hashcode, toString methods br> @Setter: annotations on attributes; Provides setting methods for properties
@Getter: annotations on attributes; provides gettin for properties G Method
@Log4j: Annotations on classes; Provides a log4j log object with a property name of log
@NoArgsConstr Uctor: Annotations on classes; provides an argument-free construction method for a class
@AllArgsConstructor: Annotations on a class, and a method to construct a full parameter for a class
Lombok simplifying Java code