我有带日期字段的域对象 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 技术使用 Example
和 ExampleMatcher
将实体实例转换为底层查询。 current official documentation阐明只有精确匹配可用于非字符串属性。由于您的需求涉及 java.util.Date
字段,您只能通过示例查询技术进行精确匹配。
您可以编写自己的 ExampleMatcher
来根据您的需要返回查询子句。
关于spring - 按示例查询 Spring 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39552467/