【问题标题】:Spring Boot Couchbase Reactive isn't supporting PaginationSpring Boot Couchbase Reactive 不支持分页
【发布时间】:2020-12-21 10:16:06
【问题描述】:

我正在尝试在我的 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);
}

【问题讨论】:

    标签: spring-data couchbase spring-webflux spring-data-couchbase spring-reactive


    【解决方案1】:

    简短的回答是文档不是最新的,最好的解决方案是像您所做的那样使用限制和偏移量自己实现分页。 https://jira.spring.io/browse/DATACOUCH-588 正在解决这个问题(那里没有描述,但这是跟踪问题)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-03
      • 2015-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 2020-02-25
      相关资源
      最近更新 更多