hibernate 如何使用Sping Boot 3过滤数据

hxzsmxv2  于 2023-10-23  发布在  其他
关注(0)|答案(1)|浏览(197)

我正在尝试使用Sping Boot 3和Hibernate 6构建一个电子商务API。我被过滤Products.Java类卡住了。我在互联网上找不到任何结果。如何使用Hibernate 6过滤这些字段?我需要一个方法来做到这一点,如果有人能提供我会很感激。

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

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

    @Column(nullable = false)
    @Size(min = 10, message = "{validation.sku.size.too_short}")
    @Size(max = 100, message = "{validation.sku.size.too_long}")
    private String sku;

    @Column(nullable = false)
    @Size(min = 5, message = "{validation.title.size.too_short}")
    @Size(max = 150, message = "{validation.title.size.too_long}")
    private String title;

    @Column(length = 300)
    private String short_desc;

    @Column
    private String long_desc;

    @Column
    private BigDecimal price;

    @Column
    private BigDecimal tax;

    @Min(0)
    @Max(100)
    @Column
    private int discount;

    @Column
    private int stock_amount;

    @Column
    private int stock_alarm_limit;

    @NotBlank
    @Size(min = 5, max = 200)
    @URL
    @Column(nullable = false, length = 200)
    private String slug;

    @Column(nullable = false)
    private boolean featured = false;

    @Column
    private String image;

    @Column
    private boolean new_product;

    @Column
    private int likes = 0;

    @NotNull(message = "Status field can not be null")
    @Column(nullable = false)
    private StatusZeroAndOne status;

    @Column
    private double witdh;

    @Column
    private double length;

    @Column
    private double height;

    @Column
    private boolean builtIn = false;
    
    

    @NotNull(message = "Please provide your brand")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "brand_id", referencedColumnName = "id", nullable = false)
    private Brand brand;

    @NotNull(message = "Please provide your category")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "category_id", referencedColumnName = "id", nullable = false)
    private Category category;

    @NotNull(message = "Creation Time can not be null")
    @CreationTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
    @Column(name = "create_at", updatable = false, nullable = false)
    private OffsetDateTime createAt;

    @UpdateTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
    @Column(name = "update_at")
    private OffsetDateTime updateAt;

}

我在网上看了看,他们说我不能在Hibernate 6中使用Criteria API。我正在寻找一个最佳做法来过滤这些数据可选。

92dk7w1h

92dk7w1h1#

你的问题不清楚。请通过提及用于过滤的属性来询问具体示例。

相关问题