跳转至

实体类

属性的名称和数据库字段名对应。

package com.hh.pojo;

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

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public Book() {
    }

    //构造器
    public Book(int id, String name, String author, double price) {
        this.id = id;
        this.name = name;
        this.author = author;
        this.price = price;
    }
}

Lombok

Lombok 是一个用于 Java 编程的库,它通过注解减少样板代码,例如 getter、setter、构造函数、equalshashCodetoString 方法的编写,从而提高开发效率和代码可读性。常用的注解包括 @Getter@Setter@ToString@EqualsAndHashCode@NoArgsConstructor@AllArgsConstructor@Data 等。

除了pom.xml引入依赖,还需在插件中添加settings-->Plugins-->lombok

<!--简化pojo类的编写-->
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>${lombok.version}</version>
    <scope>provided</scope>
</dependency>