如何通过Spring Data中的示例在两个日期之间添加限制范围 [英] How to add restriction to range between two dates on query by example in Spring Data
问题描述
我有一个包含两个日期的类,我的搜索是动态的,Hibernate提供了Query By Example(QBE),但现在使用Spring Data的QBE。问题是当创建一个QBE,但文档限制了String类型的ExampleMatcher,我需要创建一个ExampleMatcher来搜索这个日期之间的所有实体。
-
现在我的选择是:
-
创建一个hibernate dao并使用QBE和hibernate标准(Bye JPA:'()
-
探索这个 http://spring.io/blog/2011/04/26/advanced- spring-data-jpa-specifications-and-querydsl / (真丑)
private int id;
private String property1;
private String property2;
私人日期dateFirst;
私人日期dateSecond;
相关:
-
- 春季数据 JPA:Example by Query? 简短的回答是的,你没有。通过示例查询被认为正是它的名字所暗示的:你举了一个例子,并且查询建立在给定字段的匹配上。这也记录在限制链接到的参考文档部分。
Create a hibernate dao and use QBE and criteria of hibernate (Bye JPA :'( )
Explore this http://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/ (really ugly code)
$ b
有关更高级的用例和谓词定义,请查看Querydsl支持。 >
I have one class with two dates and my search is dynamic, Hibernate provides Query By Example (QBE), but now use QBE of Spring Data. The problem is when created a QBE but the documentation restrict the ExampleMatcher for String types, i need create a ExampleMatcher for search all entities between in this dates.
How implement this using query by example?.
My alternatives for now is:
Example properties for class:
private int id;
private String property1;
private String property2;
private Date dateFirst;
private Date dateSecond;
Related :
http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#query-by-example.usage
How to combine multiple date-between searches with CrudRepository of Spring Data JPA?
The short answer is, you don't. Query by example is considered exactly what its name suggests: you give an example and the query is built on a match of the given fields. That's also documented in the "Limitations" section of the reference documentation you linked to.
For more advanced use cases and predicate definitions, have a look at the Querydsl support.
这篇关于如何通过Spring Data中的示例在两个日期之间添加限制范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!