2

I am trying to configure Pageable and PageRequest for page number starting from 1 instead of 0. Using below code Pageable is configured successfully:

@Configuration 
@EnableSpringDataWebSupport 
public class JPAConfiguration { 

    @Bean 
    Pageable HandlerMethodArgumentResolverCustomizer pageCustomizer(){ 
        returns -> p.setOneIndexedParameters(true); 
    } 

} 

And now if I call endpoint using:

/myEndpoint?page=1&size=2

I get the records of first page which means 1-based page size is working. However the response has below information related to pagination:

"totalElements": 9, 
"last": false, 
"totalPages": 5, 
"size": 2, 
"number": 0, 
"numberOfElements": 2, 
"first": true, 
"sort": { 
    "sorted": true, 
    "unsorted": false 
} 

If you notice the 'number' is 0 which means it is still 0-based. How can I configure it to be 1-based?

Thanks in advance.

I am using: SpringBoot:2.0.0, spring-data-commons: 2.0.5

muneebShabbir
  • 2,500
  • 4
  • 29
  • 46
Jaffy
  • 575
  • 1
  • 6
  • 15
  • you see [that post](https://stackoverflow.com/questions/28134451/reconfigure-spring-data-rest-to-index-at-page-1)? – Patrick Mar 07 '18 at 07:34
  • As I am not using Repository Rest, so I am not sure if it works for me or not. – Jaffy Mar 07 '18 at 08:14

0 Answers0