spring data jpa limit pagesize, how to set to maxSize

后端 未结 12 2538
自闭症患者
自闭症患者 2020-12-15 20:09

I have one requirement is to search by pageable and non-pageable,

and in my Java code, I use spring data jpa Pageable class,

 Pageable pageable = new         


        
12条回答
  •  一个人的身影
    2020-12-15 20:45

    Here is a working solution for Spring 5.x.x. You just need to add the default constructor. See the above example :

    @Configuration
    public class PaginationConfiguration extends SpringDataWebConfiguration {
    
        /**
         * @param context           must not be {@literal null}.
         * @param conversionService must not be {@literal null}.
         */
        public PaginationConfiguration(ApplicationContext context,
                                       @Qualifier("mvcConversionService") ObjectFactory conversionService) {
            super(context, conversionService);
        }
    
        @Bean
        public PageableHandlerMethodArgumentResolver pageableResolver() {
            PageableHandlerMethodArgumentResolver pageableHandlerMethodArgumentResolver =
                    new PageableHandlerMethodArgumentResolver(sortResolver());
    
            pageableHandlerMethodArgumentResolver.setMaxPageSize(Integer.MAX_VALUE);
    
            return pageableHandlerMethodArgumentResolver;
        }
    
    }
    

提交回复
热议问题