当前位置:网站首页>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
边栏推荐
- Oracle database synonym creation
- Understand expectations (mean / estimate) and variances
- Zhiniu stock -- 03
- tabbar的设置
- Why should there be a firewall? This time xiaowai has something to say!!!
- CKA certification notes - CKA certification experience post
- 1. 两数之和
- Use abp Zero builds a third-party login module (I): Principles
- When PHP uses env to obtain file parameters, it gets strings
- Oracle Database Introduction
猜你喜欢

Mysql

Kubernetes notes (IV) kubernetes network

Oauth2.0 - Introduction and use and explanation of authorization code mode

Zhiniu stock project -- 04

Kubernetes notes (VII) kuberetes scheduling

Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency

最大似然估计,散度,交叉熵

Selenium ide installation recording and local project maintenance

Pytorch builds the simplest version of neural network

arcgis创建postgre企业级数据库
随机推荐
YOLOV1学习笔记
项目总结--2(Jsoup的基本使用)
Detailed explanation of findloadedclass
PMP notes
Solve the problem that Anaconda environment cannot be accessed in PowerShell
Openresty best practices
【系统设计】邻近服务
Pytorch builds the simplest version of neural network
代码管理工具
arcgis创建postgre企业级数据库
Kubernetes cluster environment construction & Deployment dashboard
Kubernetes notes (V) configuration management
1. Somme des deux nombres
Kubernetes notes (I) kubernetes cluster architecture
Phpstudy setting items can be accessed by other computers on the LAN
BeanDefinitionRegistryPostProcessor
Svn branch management
智牛股项目--05
Tabbar settings
Introduction to software engineering