2016-09-17 70 views
3

我有域对象人用日期字段:实例查询春季数据

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

建立这样的例子:

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

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

回答

1

Spring Data JPA查询示例技术使用Example s和ExampleMatcher s将实体实例转换为基础查询。 current official documentation阐明只有精确匹配可用于非字符串属性。由于您的要求涉及java.util.Date字段,因此只能与按示例查询技术进行精确匹配。

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