1
votes

My spring boot applications controller contains a method as below with optional Pageable parameter.

@RequestMapping(method = RequestMethod.GET)
@Override
public Page<MarkupView> getAllMarkup(Pageable pageable) {
    System.out.println("Page size" + pageable.getPageSize() ) // prints 20
    return markupService.getAllMarkups(pageable);
}

My problem is when I pass query parameters with swagger-ui those values does not bind to the pageable object. Why I said that is it prints pageSize as 20 whether I pass value 5 as query parameter.

request URL : http://localhost:8080/api/markups?offset=2&pageNumber=1&pageSize=5

above Get request returns me Page object which contains all MarkupView records.

2
I use page=1&size=5 instead of pageNumber &pageSize - Sachini Wickramaratne
Your parameters have the wrong name. You should be using page and size instead. See docs.spring.io/spring-data/jpa/docs/current/reference/html/… - M. Deinum
Thanks all, Its works, But I wonder why does swgger-ui take those parameters like I used above. :) - Sachithra Wishwamal

2 Answers

2
votes

By referring to section 5 of Spring Data Web Support. Please check if you follow the configuration mentioned. Then update the query parameter name from pageNumber to page and pageSize to size.

-2
votes

I am not sure why you implemented it like that. I would rather take in the request parameters in as is and then set them in a pojo instead of doing this. I tested this on my machine and it would bind as expected. See if the below implementation helps!

  @GetMapping("/api/markups")
  @Override
  public Page<MarkupView> getAllMarkup(final @RequestParam(name = "pageSize", required = false) Integer pageSize, final @RequestParam(name = "offset", required = false) Integer offset, final @RequestParam(name = "pageNumber", required = false) Integer pageNumber) {
    System.out.println("Page size" + pageSize ); 
    System.out.println("offset" + offset );
    System.out.println("Page number" + pageNumber );
    return markupService.getAllMarkups(pageSize,offset,pageNumber);
  }