Reconfigure Spring Data Rest to Index at Page 1

冷暖自知 提交于 2019-12-07 22:14:05

问题


I thought I had this figured out but the setting does not seem to change the index. setOneIndexedParameters(true)

@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
        resolver.setOneIndexedParameters(true);
        argumentResolvers.add(resolver);
        super.addArgumentResolvers(argumentResolvers);
    }

.... other config stuff

Expected result is that instead of the base URL for spring data rest being http://localhost:8080/api/text?page=0&size=20 it would change to http://localhost:8080/api/text?page=1&size=20 as the initial page.

Did I do this correctly or is this a bug?


回答1:


The answer was here Spring Data Rest - Configure pagination

I moved the configuration to extending RepositoryRestMvcConfiguration

@Configuration
class CustomRestMvcConfiguration extends RepositoryRestMvcConfiguration {

    @Override
    @Bean
    public HateoasPageableHandlerMethodArgumentResolver pageableResolver() {

        HateoasPageableHandlerMethodArgumentResolver resolver = super.pageableResolver();
resolver.setOneIndexedParameters(true);
return resolver;
    }
}


来源:https://stackoverflow.com/questions/28134451/reconfigure-spring-data-rest-to-index-at-page-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!