@Data : 注解在实体类上,提供类的get、set、equals、hashCode、canEqual、toString、无参构造方法。注意:没有全参构造方法。
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
/**
* 用户数据的实体类
*/
@Data
public class User implements Serializable {
private Integer uid;
private String username;
private String password;
private String salt;
private String phone;
private String email;
private Integer gender;
private String avatar;
private Integer isDelete;
}
点击compile进行编译。
public class User implements Serializable {
private Integer uid;
private String username;
private String password;
private String salt;
private String phone;
private String email;
private Integer gender;
private String avatar;
private Integer isDelete;
public User() {
}
public Integer getUid() {
return this.uid;
}
public String getUsername() {
return this.username;
}
public String getPassword() {
return this.password;
}
public String getSalt() {
return this.salt;
}
public String getPhone() {
return this.phone;
}
public String getEmail() {
return this.email;
}
public Integer getGender() {
return this.gender;
}
public String getAvatar() {
return this.avatar;
}
public Integer getIsDelete() {
return this.isDelete;
}
public void setUid(final Integer uid) {
this.uid = uid;
}
public void setUsername(final String username) {
this.username = username;
}
public void setPassword(final String password) {
this.password = password;
}
public void setSalt(final String salt) {
this.salt = salt;
}
public void setPhone(final String phone) {
this.phone = phone;
}
public void setEmail(final String email) {
this.email = email;
}
public void setGender(final Integer gender) {
this.gender = gender;
}
public void setAvatar(final String avatar) {
this.avatar = avatar;
}
public void setIsDelete(final Integer isDelete) {
this.isDelete = isDelete;
}
public boolean equals(final Object o) {
if (o == this) {
return true;
} else if (!(o instanceof User)) {
return false;
} else {
User other = (User)o;
if (!other.canEqual(this)) {
return false;
} else {
label119: {
Object this$uid = this.getUid();
Object other$uid = other.getUid();
if (this$uid == null) {
if (other$uid == null) {
break label119;
}
} else if (this$uid.equals(other$uid)) {
break label119;
}
return false;
}
Object this$gender = this.getGender();
Object other$gender = other.getGender();
if (this$gender == null) {
if (other$gender != null) {
return false;
}
} else if (!this$gender.equals(other$gender)) {
return false;
}
label105: {
Object this$isDelete = this.getIsDelete();
Object other$isDelete = other.getIsDelete();
if (this$isDelete == null) {
if (other$isDelete == null) {
break label105;
}
} else if (this$isDelete.equals(other$isDelete)) {
break label105;
}
return false;
}
Object this$username = this.getUsername();
Object other$username = other.getUsername();
if (this$username == null) {
if (other$username != null) {
return false;
}
} else if (!this$username.equals(other$username)) {
return false;
}
label91: {
Object this$password = this.getPassword();
Object other$password = other.getPassword();
if (this$password == null) {
if (other$password == null) {
break label91;
}
} else if (this$password.equals(other$password)) {
break label91;
}
return false;
}
Object this$salt = this.getSalt();
Object other$salt = other.getSalt();
if (this$salt == null) {
if (other$salt != null) {
return false;
}
} else if (!this$salt.equals(other$salt)) {
return false;
}
label77: {
Object this$phone = this.getPhone();
Object other$phone = other.getPhone();
if (this$phone == null) {
if (other$phone == null) {
break label77;
}
} else if (this$phone.equals(other$phone)) {
break label77;
}
return false;
}
label70: {
Object this$email = this.getEmail();
Object other$email = other.getEmail();
if (this$email == null) {
if (other$email == null) {
break label70;
}
} else if (this$email.equals(other$email)) {
break label70;
}
return false;
}
Object this$avatar = this.getAvatar();
Object other$avatar = other.getAvatar();
if (this$avatar == null) {
if (other$avatar != null) {
return false;
}
} else if (!this$avatar.equals(other$avatar)) {
return false;
}
return true;
}
}
}
protected boolean canEqual(final Object other) {
return other instanceof User;
}
public int hashCode() {
int PRIME = true;
int result = 1;
Object $uid = this.getUid();
int result = result * 59 + ($uid == null ? 43 : $uid.hashCode());
Object $gender = this.getGender();
result = result * 59 + ($gender == null ? 43 : $gender.hashCode());
Object $isDelete = this.getIsDelete();
result = result * 59 + ($isDelete == null ? 43 : $isDelete.hashCode());
Object $username = this.getUsername();
result = result * 59 + ($username == null ? 43 : $username.hashCode());
Object $password = this.getPassword();
result = result * 59 + ($password == null ? 43 : $password.hashCode());
Object $salt = this.getSalt();
result = result * 59 + ($salt == null ? 43 : $salt.hashCode());
Object $phone = this.getPhone();
result = result * 59 + ($phone == null ? 43 : $phone.hashCode());
Object $email = this.getEmail();
result = result * 59 + ($email == null ? 43 : $email.hashCode());
Object $avatar = this.getAvatar();
result = result * 59 + ($avatar == null ? 43 : $avatar.hashCode());
return result;
}
public String toString() {
Integer var10000 = this.getUid();
return "User(uid=" + var10000 + ", username=" + this.getUsername() + ", password=" + this.getPassword() + ", salt=" + this.getSalt() + ", phone=" + this.getPhone() + ", email=" + this.getEmail() + ", gender=" + this.getGender() + ", avatar=" + this.getAvatar() + ", isDelete=" + this.getIsDelete() + ")";
}
}
查看编译后的代码可以看到有get、set、equals、hashCode、canEqual、toString、无参构造方法,并没有全参构造方法。
想要全参构造方法需要添加 @AllArgsConstructor 注解。