Spring pageable - start index with one
By default Spring uses 0 indexed page meaning a page number of 0 in the request equals the first p 2020-9-14 03:5:0 Author: blog.gtiwari333.com(查看原文) 阅读量:21 收藏

By default Spring uses 0 indexed page meaning a page number of 0 in the request equals the first page.

You can customize this to start from 1 in following by creating a bean of PageableHandlerMethodArgumentResolverCustomizer and setting the setOneIndexedParameters to true.

You can read  more about the method argument resolver and other customizations to pagable in my earlier blog post:  https://ganeshtiwaridotcomdotnp.blogspot.com/2020/09/spring-data-pagination-set-max-page.html

Configures whether to expose and assume 1-based page number indexes in the request parameters. When its true, a page number of 1 in the request will be considered the first page.

@Bean
public PageableHandlerMethodArgumentResolverCustomizer paginationCustomizer() {
return pageableResolver -> {
pageableResolver.setOneIndexedParameters(true); //default is false, starts with 0
};
}

Now you can have your pagination url to start with page=1 eg: /users?size=20&page=1.


文章来源: http://blog.gtiwari333.com/2020/09/spring-pageable-start-index-with-one.html
如有侵权请联系:admin#unsafe.sh