Set default page size for JPA Pageable Object

后端 未结 8 1732
忘掉有多难
忘掉有多难 2020-12-01 09:11

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

相关标签:
8条回答
  • 2020-12-01 10:11

    You can set below in application.yml

    spring.data.rest.default-page-size: 50
    
    0 讨论(0)
  • In Spring Boot 2.1.6.RELEASE, you can use below:

    @Configuration
    public class WebConfig implements WebMvcConfigurer{
    
        @Value("${paging.default.pageSize}")
        private int size;
    
        @Value("${paging.default.page}")
        private int page;
    
    
        @Override
        public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
            PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
            resolver.setFallbackPageable(PageRequest.of(page, size));
            resolvers.add(resolver);
            WebMvcConfigurer.super.addArgumentResolvers(resolvers);
        }
    }
    
    0 讨论(0)
提交回复
热议问题