简体   繁体   English

查询示例Spring数据

[英]Query by Example Spring Data

I have domain object Person with date fields: 我有域对象Person与日期字段:

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

Build example like this: 像这样构建示例:

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

How i can create example query with date range (search entity contains date greater or equal from some date and less or equal some another date)? 如何创建具有日期范围的示例查询(搜索实体包含从某个日期开始大于或等于的日期以及更少或等于某个其他日期)?

The Spring Data JPA query-by-example technique uses Example s and ExampleMatcher s to convert entity instances into the underlying query. Spring Data JPA按示例查询技术使用ExampleExampleMatcher将实体实例转换为基础查询。 The current official documentation clarifies that only exact matching is available for non-string attributes. 当前的官方文档阐明了只有非字符串属性才能进行精确匹配。 Since your requirement involves a java.util.Date field, you can only have exact matching with the query-by-example technique. 由于您的需求涉及java.util.Date字段,因此您只能与逐个查询技术完全匹配。

You could write your own ExampleMatcher that returns query clauses according to your needs. 您可以编写自己的ExampleMatcher ,根据您的需要返回查询子句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM