记录下lombok插件下遇到的坑。
在实体类中使用lombok插件要注意属性的命名,插件不区分大小写。
import lombok.Data;
import java.util.List;
@Data
public class LombokDTO {
public String userName;
public Integer username;
public List<Long> userNAME;
}
这个实体类的命名就是其中大小写不一样,在代码编写的途中正常使用set/get方法也不会报错,但用maven打包的时候username,userNAME就会报找不到set/get方法导致报错失败。
这个可以查看target中的打包文件就能知道原因。
package com.xh.cmp.core.dto;
import java.util.List;
public class LombokDTO {
public String userName;
public Integer username;
public List<Long> userNAME;
public LombokDTO() {
}
public String getUserName() {
return this.userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (!(o instanceof LombokDTO)) {
return false;
} else {
LombokDTO other = (LombokDTO)o;
if (!other.canEqual(this)) {
return false;
} else {
label47: {
Object this$username = this.getUserName();
Object other$username = other.getUserName();
if (this$username == null) {
if (other$username == null) {
break label47;
}
} else if (this$username.equals(other$username)) {
break label47;
}
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;
}
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;
}
return true;
}
}
}
protected boolean canEqual(Object other) {
return other instanceof LombokDTO;
}
public int hashCode() {
int PRIME = true;
int result = 1;
Object $username = this.getUserName();
int result = result * 59 + ($username == null ? 43 : $username.hashCode());
Object $userName = this.getUserName();
result = result * 59 + ($userName == null ? 43 : $userName.hashCode());
Object $userNAME = this.getUserName();
result = result * 59 + ($userNAME == null ? 43 : $userNAME.hashCode());
return result;
}
public String toString() {
return "LombokDTO(userName=" + this.getUserName() + ", username=" + this.getUserName() + ", userNAME=" + this.getUserName() + ")";
}
}
看完打包后的文件,就可以看到lombok插件只生成了第一个方法,其他两个没有生成。导致maven打包后也找不到set/get方法报错。
结论:实体类使用lombok插件要注意实体属性的命名。