spring - Springboot JPA Pageable not working for page number greater then 0 -


i want results paginated, below code works fine if request made page parameter set 0 doesn't work page>0 page=1 or page=2 or page=3 etc.

here requestmapping

myresponse getsample(@modelattribute myrequest myrequest) {         pageable pagerequest =  new pagerequest(myrequest.page, myrequest.size)         mymodule.findsamples(myrequest, pagerequest)     }    class myrequest {      myquerytype querytype       string searchterm       @min(value = 0l, message = 'offset must greater or equal 0')     int offset = 0      @min(value = 0l, message = 'offset must greater or equal 0')     int page = 0      @min(value = 1l, message = 'limit must greater or equal 1')     int limit = 100      @min(value = 1l, message = 'limit must greater or equal 1')     int size = 5 }   mymodule:code inside module    myresponse findsamples(myrequest myrequest, pageable pagerequest) {             log.info("page information set "+pagerequest.pagenumber+pagerequest.pagesize)             page<samplespo> pages = null             pages = myrepository.findallbyid(myrequest.id, pagerequest)             }  

repository code:

public interface samplerepository extends jparepository<sample, long> {          @query('''         select e.samples         parentsampletable e         e.id = :id     ''')     page<sample> findallbyid(@param('id') string id, pageable pagerequest) } 

you try extracting id @pathparam

method getsample annotated @getmapping params (@pathparam("id") string id, pageable pageable) , return samplerepository.findallbyid(id, pageable)

url might like: /samples/id?page=pagenr&size=nrofelemonpage

your repository should return page<sample> findallbyid(string id, pageable pageable)

also please consider refactoring(indention) code before posting stackoverflow

also might duplicate: using findall pagingandsortingrepository filter


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -