当前位置:网站首页>Use @data in Lombok to simplify entity class code
Use @data in Lombok to simplify entity class code
2022-07-03 06:13:00 【Muyu】
While studying today , Learned to quote lombok, Methods to simplify entity class code ,
First call lombox, Before that, we have to be in setting Of plugin Download lombok Plug in for , Otherwise call get,set Method is not prompted
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
And then in pojo Add annotations to the entity class of
package com.muyu.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User{
private long id;
private String name;
private Integer age;
private String email;
}
The effect achieved is equivalent to this
package com.muyu.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
public class User{
private long id;
private String name;
private Integer age;
private String email;
public User() {
}
public User(long id, String name, Integer age, String email) {
this.id = id;
this.name = name;
this.age = age;
this.email = email;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
if (id != user.id) return false;
if (name != null ? !name.equals(user.name) : user.name != null) return false;
if (age != null ? !age.equals(user.age) : user.age != null) return false;
return email != null ? email.equals(user.email) : user.email == null;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (age != null ? age.hashCode() : 0);
result = 31 * result + (email != null ? email.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", email='" + email + '\'' +
'}';
}
}
The following is a detailed explanation of usage
- @Data : Annotation on class ; Providing all properties of the class getting and setting Method , It also provides equals、hashCode、toString Method
- @Setter: Comment on attribute ; Provide... For properties setting Method
- @Getter: Comment on attribute ; Provide... For properties getting Method
- @Log4j : Annotation on class ; Provide a... For the class Properties, log Of log4j Log object
- @NoArgsConstructor: Annotation on class ; Provides a parameterless construction method for a class
- @AllArgsConstructor: Annotation on class ; Provide a construction method of all parameters for the class
边栏推荐
猜你喜欢

Deep learning, thinking from one dimensional input to multi-dimensional feature input

Kubesphere - build Nacos cluster

YOLOV2学习与总结

JMeter performance automation test

智牛股--03

Oauth2.0 - explanation of simplified mode, password mode and client mode

Kubernetes notes (II) pod usage notes

Core principles and source code analysis of disruptor

深入解析kubernetes controller-runtime

Jedis source code analysis (I): jedis introduction, jedis module source code analysis
随机推荐
Leetcode problem solving summary, constantly updating!
Skywalking8.7 source code analysis (I): agent startup process, agent configuration loading process, custom class loader agentclassloader, plug-in definition system, plug-in loading
Mysql
The programmer shell with a monthly salary of more than 10000 becomes a grammar skill for secondary school. Do you often use it!!!
Characteristics and isolation level of database
Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
MySQL帶二進制的庫錶導出導入
SQL实现将多行记录合并成一行
Zhiniu stock project -- 04
项目总结--2(Jsoup的基本使用)
Kubernetes notes (IX) kubernetes application encapsulation and expansion
深度学习,从一维特性输入到多维特征输入引发的思考
Mysql database
Kubernetes notes (VIII) kubernetes security
代码管理工具
Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
Pytorch dataloader implements minibatch (incomplete)
Convolution operation in convolution neural network CNN
PMP笔记记录
Alibaba cloud OOS file upload