关于Lombok包下,Model之上,使用@Data做了什么工作

自建的Model(Lombok下的@Data)

package dockerDemo1.model;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Book {

    private String id;

    private String name;

    private String author;

    private String price;

}

Maven编译后的代码

package dockerDemo1.model;

public class Book {
    private String id;
    private String name;
    private String author;
    private String price;

    public Book() {
    }
    public String getId() {
        return this.id;
    }
    public String getName() {
        return this.name;
    }
    public String getAuthor() {
        return this.author;
    }

    public String getPrice() {
        return this.price;
    }
	public Book setId(final String id) {
        this.id = id;
        return this;
    }
    public Book setName(final String name) {
        this.name = name;
        return this;
    }

    public Book setAuthor(final String author) {
        this.author = author;
        return this;
    }
    public Book setPrice(final String price) {
        this.price = price;
        return this;
    }
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Book)) {
            return false;
        } else {
            Book other = (Book)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label59: {
                    Object this$id = this.getId();
                    Object other$id = other.getId();
                    if (this$id == null) {
                        if (other$id == null) {
                            break label59;
                        }
                    } else if (this$id.equals(other$id)) {
                        break label59;
                    }

                    return false;
                }
                Object this$name = this.getName();
                Object other$name = other.getName();
                if (this$name == null) {
                    if (other$name != null) {
                        return false;
                    }
                } else if (!this$name.equals(other$name)) {
                    return false;
                }
                Object this$author = this.getAuthor();
                Object other$author = other.getAuthor();
                if (this$author == null) {
                    if (other$author != null) {
                        return false;
                    }
                } else if (!this$author.equals(other$author)) {
                    return false;
                }
                Object this$price = this.getPrice();
                Object other$price = other.getPrice();
                if (this$price == null) {
                    if (other$price != null) {
                        return false;
                    }
                } else if (!this$price.equals(other$price)) {
                    return false;
                }
                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof Book;
    }

    public int hashCode() {
        int PRIME = true;
        int result = 1;
        Object $id = this.getId();
        int result = result * 59 + ($id == null ? 43 : $id.hashCode());
        Object $name = this.getName();
        result = result * 59 + ($name == null ? 43 : $name.hashCode());
        Object $author = this.getAuthor();
        result = result * 59 + ($author == null ? 43 : $author.hashCode());
        Object $price = this.getPrice();
        result = result * 59 + ($price == null ? 43 : $price.hashCode());
        return result;
    }
    public String toString() {
        return "Book(id=" + this.getId() + ", name=" + this.getName() + ", author=" + this.getAuthor() + ", price=" + this.getPrice() + ")";
    }
}

@Data其实就是做了,自动生成Model的get,set方法,还有hashcode,equal,tostring方法

下一篇,使用Lombok包,应注意的细节,记录一次入坑示例

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务