"spring.data.web.pageable.one-indexed-parameters = true";不起作用 [英] "spring.data.web.pageable.one-indexed-parameters=true" does not work
问题描述
在我的Spring Boot Rest Service中,我想实现带有分页的getAll方法,以便稍后在前端进行延迟加载.
in my Spring Boot Rest Service I want to implement a getAll method with pagination for lazy loading in frontend later.
目前,如果我要第一组行,则必须请求第0页.在application.properties中插入以下配置后,它应该可以工作... spring.data.web.pageable.one-indexed-parameters = true ...但事实并非如此.
At the moment I have to request with page 0 if I want the first set of rows. With the following config inserted in the application.properties it should work... spring.data.web.pageable.one-indexed-parameters=true ... but it doesn't.
有人知道这是为什么还是传统的方法吗?我正在使用2.0.4.RELEASE版本中的spring-boot-starter-web和data-jpa.
Does anybody knows why or is this a legacy way? I'm using spring-boot-starter-web and data-jpa in version 2.0.4.RELEASE.
非常感谢!
编辑,这是服务方法,也许PageRequest无法处理此问题.
edit, here is the service method, maybe PageRequest can't handle this.
public List<TransactionResponseDTO> findAll(int pageNumber, int pageSize) {
List<TransactionResponseDTO> transactionResponseDTOs = new ArrayList<>();
PageRequest pageRequest = PageRequest.of(pageNumber, pageSize);
List<TransactionEntity> transactionEntities =
transactionRepository.findAll(pageRequest).getContent();
for (TransactionEntity transactionEntity : transactionEntities) {
transactionResponseDTOs.add(convert(transactionEntity));
}
return transactionResponseDTOs;
}
推荐答案
我认为这是bug.参见 https://github.com/spring-projects/spring-boot/issues /14413
i think that is bug . see https://github.com/spring-projects/spring-boot/issues/14413
"SpringDataWebAutoConfiguration"应在"RepositoryRestMvcAutoConfiguration"之前,这会使"PageableHandlerMethodArgumentResolverCustomizer"无法正常工作,因此cofig yml的"spring.data.web.pageable"无法正常工作
'SpringDataWebAutoConfiguration'should before'RepositoryRestMvcAutoConfiguration',this makes 'PageableHandlerMethodArgumentResolverCustomizer' not work ,so cofig yml ‘spring.data.web.pageable’ not work
这篇关于"spring.data.web.pageable.one-indexed-parameters = true";不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!