Spring Boot Couchbase Reactive不支持分页

问题描述

我正在尝试在Reactive WebFlux应用程序中实现分页,并且我的数据库是Couchbase。

The Spring Data Couchbase doc允许我在存储库中将Pageable作为参数传递。

Flux<Person> findByFirstnameOrderByLastname(String firstname,Pageable pageable);

但是,当我尝试实现它时,出现以下错误:

Caused by: java.lang.IllegalStateException: Method has to have one of the following return types! [interface org.springframework.data.domain.Slice,interface java.util.List,interface org.springframework.data.domain.Page]

我的存储库方法如下:

Flux<Building> findAll(Pageable pageable);

但是,如果我使用此替代方法,则没有问题。

@Query("#{#n1ql.selectEntity} where #{#n1ql.filter} LIMIT $1 OFFSET $2")
Flux<Building> findAll(Integer limit,Integer offset);

这是一个错误吗?或者,我使用错了吗?

Spring Boot版本: 2.2.7.RELEASE

完整存储库:

@Repository
public interface BuildingRepository extends ReactiveSortingRepository<Building,String> {

    @Query("#{#n1ql.selectEntity} where #{#n1ql.filter} LIMIT $1 OFFSET $2")
    Flux<Building> findAll(Integer limit,Integer offset);

    //This works if I comment the below
    Flux<Building> findAll(Pageable pageable);
}

解决方法

最简单的答案是文档不是最新的,最好的解决方案是像执行操作一样使用限制和偏移量实现分页。 https://jira.spring.io/browse/DATACOUCH-588中正在对此进行补救(此处没有描述,但这是跟踪问题)

即使如此,更有效的分页方法是键集分页(https://use-the-index-luke.com/no-offset)-但您需要在应用程序中实现它。它使用索引来获取从所需的第一个项目开始的项目,而不是“跳过”先前页面中的项目。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...