以下是一个简单的商品表的 Java 实体类示例:

import javax.persistence.*;

@Entity
@Table(name = "product")
public class Product {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "name")
    private String name;

    @Column(name = "price")
    private Double price;

    @Column(name = "description")
    private String description;

    // 构造函数
    public Product() {}

    public Product(String name, Double price, String description) {
        this.name = name;
        this.price = price;
        this.description = description;
    }

    // Getter和Setter方法
    public Long getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

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

    public Double getPrice() {
        return price;
    }

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

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    // toString方法
    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", name='" + name + "'"
                ", price=" + price +
                ", description='" + description + "'"
                + "}";
    }
}

这个实体类使用了 JPA 的注解进行数据库映射,包括了 id、name、price 和 description 等属性。同时提供了构造函数和 Getter/Setter 方法,以及一个 toString 方法用于打印实体类的信息。

Java 商品表实体类示例 - 数据库映射与属性定义

原文地址: https://www.cveoy.top/t/topic/o2aT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录