Lombok plugin,
IDE:
IntelliJ IDEA
First install lombok in the configured plug-in bar, and then use the following pom dependency:
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional></dependency>
Annotations:
Generate the toString () method. By default, it prints your class name and each field in order (separated by commas. You can set the fields that do not contain @ ToString (exclude = "id")/@ ToString (exclude = {"id", "name"}). If the inherited fields have parent classes, you can set callSuper to call the toString () method of the parent class, for example, @ ToString (callSuper = true)
Import lombok. toString; @ ToString (exclude = {"id", "name"}) public class User {private Integer id; private String name; private String phone ;} // The toString generation method is as follows: public String toString () {return "User (phone =" + phone + ")";}
You can use @ Getter/@ Setter to comment out any field, so that lombok can automatically generate the default getter/setter method. The default method is public. To modify the method modifier, you can set the value of AccessLevel, for example, @ Getter (access = AccessLevel. PROTECTED)
import lombok.AccessLevel;import lombok.Getter;import lombok.Setter;public class User { @Getter(AccessLevel.PROTECTED) @Setter private Integer id; @Getter @Setter private String name; @Getter @Setter private String phone;}
Generate hashCode () and equals () methods,
By default, it uses all non-static and non-transient fields. However, you can exclude more fields by using the optional exclude parameter. Alternatively, you can name them in the parameter to specify the fields you want to use.
- @ RequiredArgsConstructor
@ RequiredArgsConstructor: A constructor generates a constructor (which may contain parameters or not). If a constructor contains parameters, this parameter can only be a final modified uninitialized field, or an uninitialized field @ RequiredArgsConstructor (staticName = "of") annotated with @ NonNull will generate a static method of () and set the constructor to private
@ Data contains the functions of @ ToString, @ javassandhashcode, @ Getter/@ Setter, and @ RequiredArgsConstructor.
More useful information will be added in the future.