" spring.data.web.pageable.one-indexed-parameters = true"不起作用 [英] "spring.data.web.pageable.one-indexed-parameters=true" does not work

查看:486
本文介绍了" spring.data.web.pageable.one-indexed-parameters = true"不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的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;
}

推荐答案

@Configuration
public class PageableConfig {

    @Bean
    PageableHandlerMethodArgumentResolverCustomizer pageableResolverCustomizer() {
        return pageableResolver -> pageableResolver.setOneIndexedParameters(true);
    }
}

这篇关于&quot; spring.data.web.pageable.one-indexed-parameters = true&quot;不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆