Query by Example Spring Data

你离开我真会死。 提交于 2019-11-30 19:42:01

问题


I have domain object Person with date fields:

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)?


回答1:


The Spring Data JPA query-by-example technique uses Examples and ExampleMatchers to convert entity instances into the underlying query. 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.

You could write your own ExampleMatcher that returns query clauses according to your needs.



来源:https://stackoverflow.com/questions/39552467/query-by-example-spring-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!