我以为我已经弄清楚了,但是设置似乎并没有改变索引。 setOneIndexedParameters(true)
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
预期结果是它将代替spring数据的基本URL,http://localhost:8080/api/text?page=0&size=20而是将其更改http://localhost:8080/api/text?page=1&size=20为初始页面。
http://localhost:8080/api/text?page=0&size=20
http://localhost:8080/api/text?page=1&size=20
我这样做正确还是错误?
我将配置移至扩展 RepositoryRestMvcConfiguration
RepositoryRestMvcConfiguration
@Configuration class CustomRestMvcConfiguration extends RepositoryRestMvcConfiguration { @Override @Bean public HateoasPageableHandlerMethodArgumentResolver pageableResolver() { HateoasPageableHandlerMethodArgumentResolver resolver = super.pageableResolver(); resolver.setOneIndexedParameters(true); return resolver; } }