我以为我已经想到这个,但设置似乎没有改变索引。 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
预期结果是,弹出数据的基本网址不是http://localhost:8080/api/text?page=0&size=20
,而是将其更改为http://localhost:8080/api/text?page=1&size=20
作为初始页面。
我是否正确执行此操作或这是一个错误?
答案 0 :(得分:6)
答案在这里Spring Data Rest - Configure pagination
我将配置移至RepositoryRestMvcConfiguration
@Configuration
class CustomRestMvcConfiguration extends RepositoryRestMvcConfiguration {
@Override
@Bean
public HateoasPageableHandlerMethodArgumentResolver pageableResolver() {
HateoasPageableHandlerMethodArgumentResolver resolver = super.pageableResolver();
resolver.setOneIndexedParameters(true);
return resolver;
}
}