我需要在存储库中创建一个复杂的可分页过滤器。我已经成功地使用Example和Pageable扩展自:
extends JpaRepository <Card, Long>
继而从:
extends PagingAndSortingRepository <T, ID>, QueryByExampleExecutor <T>
现在的呼叫是这样的:
Page<Card> findByCreatedDateBetween (Example<Card> exampleCard, Pageable pageable);
问题:我需要按日期搜索,该日期必须在两个给定的日期之间。在Example<Card>
这是不可能指示范围。
我已经考虑过使用Specification来做到这一点,但是我不知道如何使用3个参数进行调用:
Page<Card> findByCreatedDateBetween (Specification<Card> cardSpecification, Example<Card> exampleOffer, Pageable pageable);
同样还有其他解决方案吗?
您不能在一个查询中同时使用an Example
和a Specification
,因为QueryByExampleExecutor
它不提供这种方法。
您还可以查看SimpleJpaRepository
是否对的实现感兴趣QueryByExampleExecutor
。在内部,实现创建一个Specification
从Example
使用QueryByExamplePredicateBuilder
。您可能可以使用该功能Specification
从使用该功能构建自己的Example
功能,然后将其Specification
与另一个功能结合使用。
该ExampleSpecification
中SimpleJpaRepository
是私有的,所以你不能使用,但你可以复制它,然后像做
findAll(ExampleSpecification(yourExample, escapeCharacter).and(yourDateRangeSpecification), pageable);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句