Spring Data Rest - Configure pagination

后端 未结 2 1738
暗喜
暗喜 2020-12-18 14:45

Using Spring Data REST with JPA in version 2.1.0.

How can I configure the pagination in order to have the page argument starting at index 1 instead of 0 ?

I

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-18 15:09

    The easiest way to do so is to subclass RepositoryRestMvcConfiguration and include your class into your configuration:

    class CustomRestMvcConfiguration extends RepositoryRestMvcConfiguration {
    
      @Override
      @Bean
      public HateoasPageableHandlerMethodArgumentResolver pageableResolver() {
    
        HateoasPageableHandlerMethodArgumentResolver resolver = super.pageableResolver();
        resolver.setOneIndexedParameters(true);
        return resolver;
      }
    }
    

    In your XML configuration, replace:

    
    

    with

    
    

    or import the custom class instead of the standard one in your JavaConfig file.

提交回复
热议问题