how to use SpringData findAll() between select when using an object as major condition?

Multi tool use


how to use SpringData findAll() between select when using an object as major condition?
So there's a method in SpringData findAll(Pageable pageable,Condition condition) ;
,
usually I use it like findAll(pageable,myobject)
.
findAll(Pageable pageable,Condition condition) ;
findAll(pageable,myobject)
The question is when it comes to select some records between some certain field range ,like select out objects whose createDate are between A and B , how to use findAll()
?
findAll()
I tried findAllByCreateDateAfterAndCreateDateBefore(Pageable pageable,Date a,Date b)
;
findAllByCreateDateAfterAndCreateDateBefore(Pageable pageable,Date a,Date b)
But here I can't put myObj as a condtion into the method , and it caused a lot trouble when some fields in the myObj are not sure if it would be used as a condition.
1 Answer
1
You can simply use JPA Specification to do this, then :
fun findAll(spec: Specification<YourObject>, pageable: Pageable): Page<YourObject>
Here simple example how it should be use :
JPA Specification example
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.