工作记录------lombok中@Data包含哪些功能?
在实体类中加上@Data后,实体类有哪些增强?
@Data
public class BaseProcedure {
@TableId(value = "id", type = IdType.ASSIGN_UUID)
private String id;
private String procedureCode;
写上@Data后,点击maven----clean—complie(编译)后,
查看target,能够看到编译后的实体类对象。
具体代码如下所示:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.example.demo.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
public class BaseProcedure {
@TableId(
value = "id",
type = IdType.ASSIGN_UUID
)
private String id;
private String procedureCode;
private String procedureName;
private Integer active;
private String createBy;
@DateTimeFormat(
pattern = "yy-MM-dd HH:mm:ss"
)
private Date createTime;
private String updateBy;
@DateTimeFormat(
pattern = "yy-MM-dd HH:mm:ss"
)
private Date updateTime;
public BaseProcedure() {
}
public String getId() {
return this.id;
}
public String getProcedureCode() {
return this.procedureCode;
}
public String getProcedureName() {
return this.procedureName;
}
public Integer getActive() {
return this.active;
}
public String getCreateBy() {
return this.createBy;
}
public Date getCreateTime() {
return this.createTime;
}
public String getUpdateBy() {
return this.updateBy;
}
public Date getUpdateTime() {
return this.updateTime;
}
public BaseProcedure setId(final String id) {
this.id = id;
return this;
}
public BaseProcedure setProcedureCode(final String procedureCode) {
this.procedureCode = procedureCode;
return this;
}
public BaseProcedure setProcedureName(final String procedureName) {
this.procedureName = procedureName;
return this;
}
public BaseProcedure setActive(final Integer active) {
this.active = active;
return this;
}
public BaseProcedure setCreateBy(final String createBy) {
this.createBy = createBy;
return this;
}
public BaseProcedure setCreateTime(final Date createTime) {
this.createTime = createTime;
return this;
}
public BaseProcedure setUpdateBy(final String updateBy) {
this.updateBy = updateBy;
return this;
}
public BaseProcedure setUpdateTime(final Date updateTime) {
this.updateTime = updateTime;
return this;
}
public boolean equals(final Object o) {
if (o == this) {
return true;
} else if (!(o instanceof BaseProcedure)) {
return false;
} else {
BaseProcedure other = (BaseProcedure)o;
if (!other.canEqual(this)) {
return false;
} else {
label107: {
Object this$active = this.getActive();
Object other$active = other.getActive();
if (this$active == null) {
if (other$active == null) {
break label107;
}
} else if (this$active.equals(other$active)) {
break label107;
}
return false;
}
Object this$id = this.getId();
Object other$id = other.getId();
if (this$id == null) {
if (other$id != null) {
return false;
}
} else if (!this$id.equals(other$id)) {
return false;
}
Object this$procedureCode = this.getProcedureCode();
Object other$procedureCode = other.getProcedureCode();
if (this$procedureCode == null) {
if (other$procedureCode != null) {
return false;
}
} else if (!this$procedureCode.equals(other$procedureCode)) {
return false;
}
label86: {
Object this$procedureName = this.getProcedureName();
Object other$procedureName = other.getProcedureName();
if (this$procedureName == null) {
if (other$procedureName == null) {
break label86;
}
} else if (this$procedureName.equals(other$procedureName)) {
break label86;
}
return false;
}
label79: {
Object this$createBy = this.getCreateBy();
Object other$createBy = other.getCreateBy();
if (this$createBy == null) {
if (other$createBy == null) {
break label79;
}
} else if (this$createBy.equals(other$createBy)) {
break label79;
}
return false;
}
label72: {
Object this$createTime = this.getCreateTime();
Object other$createTime = other.getCreateTime();
if (this$createTime == null) {
if (other$createTime == null) {
break label72;
}
} else if (this$createTime.equals(other$createTime)) {
break label72;
}
return false;
}
Object this$updateBy = this.getUpdateBy();
Object other$updateBy = other.getUpdateBy();
if (this$updateBy == null) {
if (other$updateBy != null) {
return false;
}
} else if (!this$updateBy.equals(other$updateBy)) {
return false;
}
Object this$updateTime = this.getUpdateTime();
Object other$updateTime = other.getUpdateTime();
if (this$updateTime == null) {
if (other$updateTime != null) {
return false;
}
} else if (!this$updateTime.equals(other$updateTime)) {
return false;
}
return true;
}
}
}
protected boolean canEqual(final Object other) {
return other instanceof BaseProcedure;
}
public int hashCode() {
int PRIME = true;
int result = 1;
Object $active = this.getActive();
result = result * 59 + ($active == null ? 43 : $active.hashCode());
Object $id = this.getId();
result = result * 59 + ($id == null ? 43 : $id.hashCode());
Object $procedureCode = this.getProcedureCode();
result = result * 59 + ($procedureCode == null ? 43 : $procedureCode.hashCode());
Object $procedureName = this.getProcedureName();
result = result * 59 + ($procedureName == null ? 43 : $procedureName.hashCode());
Object $createBy = this.getCreateBy();
result = result * 59 + ($createBy == null ? 43 : $createBy.hashCode());
Object $createTime = this.getCreateTime();
result = result * 59 + ($createTime == null ? 43 : $createTime.hashCode());
Object $updateBy = this.getUpdateBy();
result = result * 59 + ($updateBy == null ? 43 : $updateBy.hashCode());
Object $updateTime = this.getUpdateTime();
result = result * 59 + ($updateTime == null ? 43 : $updateTime.hashCode());
return result;
}
public String toString() {
return "BaseProcedure(id=" + this.getId() + ", procedureCode=" + this.getProcedureCode() + ", procedureName=" + this.getProcedureName() + ", active=" + this.getActive() + ", createBy=" + this.getCreateBy() + ", createTime=" + this.getCreateTime() + ", updateBy=" + this.getUpdateBy() + ", updateTime=" + this.getUpdateTime() + ")";
}
}
根据编译后的文件,可以看到包括了:
无参构造器、
get方法、
set方法、
hashCode方法、
equals方法、
toString方法。
结论:@Data注解相当于
@NoArgsConstructor
@Getter
@Setter
@EqualsAndHashCode
@ToString
这5个注解集合,可以看到如果需要使用到这个实体类的全参构造方法,需要再加上@AllArgsConstructor注解。
如果没有特殊需求时,只写@Data注解即可。