记录Lombok插件遇到的坑

记录下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插件要注意实体属性的命名。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值