I have a PagingandSorting Repository which has a method that accecpts a pageable object. I also have a controller that accepts a pageable object through the URL.
My use case is that, if a user specifies a page size parameter in the URL i must take that value for the pageable object. If he does not mention take a default value of 50.
But the pageable object defaults to 20 right now.
Any Suggestions would help
If you are talking about a Spring Data PagingAndSortingRepository you can set the default page size by using the
@PageableDefault
on a Controller method as follows:Or you can configure a global default using the following in your Spring config as shown below in both XML and Java config.
Note that newer versions of Spring Data use zero based page indexing while older versions used 1 for the first page. If your UI paging library expects 1 as first page then you can set the
oneIndexedParameters
property totrue
:In XML this looks like the following then:
In Java Config this looks like the below:
For Spring Boot 2.X you have set of parameters: