gpt4 book ai didi

spring - 按示例查询 Spring 数据

转载 作者:行者123 更新时间:2023-12-02 03:11:52 27 4
gpt4 key购买 nike

我有带日期字段的域对象 Person:

public class Person {
@Id
private Long id;
private Date date

像这样构建示例:

Person person = new Person();
person.setSomeOtherFields("some fields");
Example<Person> example = Example.of(person);

我如何创建具有日期范围的示例查询(搜索实体包含大于或等于某个日期且小于或等于另一个日期的日期)?

最佳答案

Spring Data JPA query-by-example 技术使用 ExampleExampleMatcher 将实体实例转换为底层查询。 current official documentation阐明只有精确匹配可用于非字符串属性。由于您的需求涉及 java.util.Date 字段,您只能通过示例查询技术进行精确匹配。

您可以编写自己的 ExampleMatcher 来根据您的需要返回查询子句。

关于spring - 按示例查询 Spring 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39552467/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com