当前位置:网站首页>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
边栏推荐
- Bio, NiO, AIO details
- Openresty best practices
- Kubesphere - build MySQL master-slave replication structure
- 项目总结--01(接口的增删改查;多线程的使用)
- 剖析虚幻渲染体系(16)- 图形驱动的秘密
- Support vector machine for machine learning
- Redis cluster creation, capacity expansion and capacity reduction
- Detailed explanation of contextclassloader
- Zhiniu stock project -- 05
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
猜你喜欢
Mysql
Detailed explanation of contextclassloader
Kubernetes notes (VIII) kubernetes security
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
Support vector machine for machine learning
Jedis source code analysis (II): jediscluster module source code analysis
Advanced technology management - do you know the whole picture of growth?
Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency
Convolution operation in convolution neural network CNN
Simple understanding of ThreadLocal
随机推荐
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
使用conda创建自己的深度学习环境
Jedis source code analysis (I): jedis introduction, jedis module source code analysis
Some thoughts on machine learning
ThreadLocal的简单理解
项目总结--01(接口的增删改查;多线程的使用)
The programmer shell with a monthly salary of more than 10000 becomes a grammar skill for secondary school. Do you often use it!!!
There is no one of the necessary magic skills PXE for old drivers to install!!!
pytorch 搭建神经网络最简版
项目总结--2(Jsoup的基本使用)
Solve the problem that Anaconda environment cannot be accessed in PowerShell
SVN分支管理
Advanced technology management - do you know the whole picture of growth?
Project summary --04
Apple submitted the new MAC model to the regulatory database before the spring conference
BeanDefinitionRegistryPostProcessor
Kubernetes notes (IV) kubernetes network
Simple understanding of ThreadLocal
Redis cluster creation, capacity expansion and capacity reduction