当前位置:网站首页>Lombok detailed introduction
Lombok detailed introduction
2022-07-25 03:15:00 【C'z x】
One 、Lombok brief introduction
Lombok It's a Java library , Can automatically insert editor and build tools , simplify Java Development . By adding comments , You don't need to write... For the class getter or eques Method , At the same time, log variables can be automated .
Simply speaking :Lombok Can be simplified in the form of simple notes java Code , Improve the development efficiency of developers .
Two 、 Lombok Installation
Introduce dependencies
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>Installing a plug-in

3、 ... and 、 Use Lombok And the difference between not using
Don't use Lombok Annotations , Everyone should write these methods , so much trouble .
public class test {
private Integer id;
private String username;
private Integer age;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "test{" +
"id=" + id +
", username='" + username + '\'' +
", age=" + age +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
test test = (test) o;
return Objects.equals(id, test.id) && Objects.equals(username, test.username) && Objects.equals(age, test.age);
}
@Override
public int hashCode() {
return Objects.hash(id, username, age);
}
}Use Lombok Annotations , Generated the required get、set、toString Other methods
@Data
public class test {
private Integer id;
private String username;
private Integer age;
}Four 、Lombok Commonly used annotations
@Setter Annotation in class or field , Annotations are generated for all fields at class time setter Method , When an annotation is on a field, it is generated only for that field setter Method .
@Getter The same as above , The difference is that what is generated is getter Method .
@ToString The annotation is in the class , add to toString Method .
@EqualsAndHashCode The annotation is in the class , Generate hashCode and equals Method .
@NoArgsConstructor The annotation is in the class , The construction method of generating parameterless .
@RequiredArgsConstructor The annotation is in the class , Generate construction methods for fields in the class that need special processing , such as final And quilt @NonNull Annotated fields .
@AllArgsConstructor The annotation is in the class , Generate the constructor that contains all the fields in the class .
@Data The annotation is in the class , Generate setter/getter、equals、canEqual、hashCode、toString Method , If final attribute , Will not generate setter Method .
@Slf4j The annotation is in the class , Generate log Variable , Strictly speaking, it's constant .private static final Logger log = LoggerFactory.getLogger(UserController.class);
边栏推荐
- JS method encapsulation summary
- Question D: pruning shrubs
- mysql_ User table_ Field meaning
- B. Making Towers
- Algorithmic interview questions
- DOM node type
- Vscode configuration, eslint+prettier combined with detailed configuration steps, standardized development
- Vscode copy synchronization plug-in expansion
- Swiper4 is used to smooth longitudinal seamless scrolling. After clicking or dragging the mouse, the animation is not completely completed, the mouse moves out of the automatic rotation, and the dynam
- Keras load history H5 format model error: attributeerror 'STR' object has no attribute 'decode‘
猜你喜欢

JS foundation -- regular expression

Define macros in makefile and pass them to source code

B. Making Towers

Unity refers to a variable in another class (its own instance)

Riotboard development board series notes (4) -- using Vpu hardware decoding

Domestic edge computing organization and product research

Learning record 12

Publish the project online and don't want to open a port

C language function operation

JS written test question -- promise, setTimeout, task queue comprehensive question
随机推荐
PHP record
JS foundation -- task queue and event loop
Query the information of students whose grades are above 80
kettle_ Configure database connection_ report errors
[jailhouse article] scheduling policies and system software architectures for mixed criticality
JS common interview questions
mysql_ Backup restore_ Specify table_ Backup table_ Restore table_ innobackup
JS written test question -- browser kernel
JS written test question -- realize the flat function of array
MySQL configuration in CDH installation
Banana pie bpi-m5 toss record (2) -- compile u-boot
mysql_ User table_ Field meaning
Solve the error: could not find 'xxxtest‘
Publish the project online and don't want to open a port
From input URL to page presentation
Import and export using poi
Function of each layer of data warehouse
Test question f: statistical submatrix
Unity refers to a variable in another class (its own instance)
Backtracking to solve subset problem