当前位置:网站首页>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
边栏推荐
- Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
- Oauth2.0 - user defined mode authorization - SMS verification code login
- Es remote cluster configuration and cross cluster search
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- Selenium ide installation recording and local project maintenance
- 輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
- Leetcode problem solving summary, constantly updating!
- ODL framework project construction trial -demo
- BeanDefinitionRegistryPostProcessor
- The programmer shell with a monthly salary of more than 10000 becomes a grammar skill for secondary school. Do you often use it!!!
猜你喜欢

Project summary --2 (basic use of jsup)

Zhiniu stock project -- 05

pytorch DataLoader实现miniBatch(未完成)

深入解析kubernetes controller-runtime

Oauth2.0 - user defined mode authorization - SMS verification code login

伯努利分布,二项分布和泊松分布以及最大似然之间的关系(未完成)

Loss function in pytorch multi classification

Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation
![[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)](/img/a4/00aca72b268f77fe4fb24ac06289f5.jpg)
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)

Core principles and source code analysis of disruptor
随机推荐
How to create and configure ZABBIX
BeanDefinitionRegistryPostProcessor
About the difference between count (1), count (*), and count (column name)
致即将毕业大学生的一封信
Simple understanding of ThreadLocal
Migrate data from Mysql to tidb from a small amount of data
Kubesphere - build Nacos cluster
The most responsible command line beautification tutorial
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
使用conda创建自己的深度学习环境
Kubernetes notes (10) kubernetes Monitoring & debugging
认识弹性盒子flex
PHP用ENV获取文件参数的时候拿到的是字符串
pytorch DataLoader实现miniBatch(未完成)
Migrate data from Amazon aurora to tidb
PMP笔记记录
Zhiniu stock project -- 04
There is no one of the necessary magic skills PXE for old drivers to install!!!
Kubernetes notes (VI) kubernetes storage
Luogu problem list: [mathematics 1] basic mathematics problems