1 year ago

#41013

test-img

Abhishek

Pageable compenent is passed as null even we pass page,size,sort object

I have a rest controller that takes pageable as a parameter

  @GetMapping(value = "/user", produces = APPLICATION_JSON_VALUE,
      consumes = APPLICATION_JSON_VALUE)
  public BaseResponse getUsers(
      Pageable pageRequest) {
      System.out.println(pageRequest);
    );
  }

now if i hit the url http://localhost:8080/user?page=1&size=20&sort=userId i can see the syso getting printed as : Page request [number: 1, size 20, sort: userId: ASC]

but if i change the controller method and make pageable as required = false

@RequestParam(required= false)Pageable pageRequest

and if i hit the same url this time my syso will print null. I want to make pageable object as not required. How to achieve it

Basically my requirement is if the user triggers the url like the below

http://localhost:8080/user?page=1&size=20&sort=userId

and when i print my Pageable object it should print Page request [number: 1, size 20, sort: userId: ASC]

but if i trigger my url like this http://localhost:8080/user then my pageable object should be printed as null and not some default values

java

spring-boot

rest

postman

pageable

0 Answers

Your Answer

Accepted video resources