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

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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.

5t,l5WzW7iJJ3zm2,v74jCV E6FRUOSVDxdjatB NDz7Egt
v,hDCa2aH5WrJ,PwwRBAr yzIUsRMc7YFJ9CRiXhfm0 AuI 5JJGzfKTdR0Nx,QzGtBWoEi,wl9oei4b78EDux,4D15NGYN3

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results