简体   繁体   English

Spring Boot Couchbase Reactive 不支持分页

[英]Spring Boot Couchbase Reactive isn't supporting Pagination

I'm trying to implement Pagination in my Reactive WebFlux app and my DB is Couchbase.我正在尝试在我的 Reactive WebFlux 应用程序中实现分页,而我的数据库是 Couchbase。

The Spring Data Couchbase doc allows me to pass Pageable as an argument in my Repository. Spring Data Couchbase 文档允许我将 Pageable 作为参数传递到我的存储库中。

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

However, when I try to implement it I get the below error:但是,当我尝试实现它时,出现以下错误:

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]

My Repository method looks like this:我的存储库方法如下所示:

Flux<Building> findAll(Pageable pageable);

However, if I use this workaround, I've no problem.但是,如果我使用此解决方法,我没有问题。

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

Is this a bug?这是一个错误吗? Or, am I using it wrong?或者,我用错了吗?

Spring Boot version: 2.2.7.RELEASE Spring 引导版本: 2.2.7.RELEASE

Full Repository:完整存储库:

@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);
}

The short answer is that the documentation is not current, and the best solution is to implement paging yourself with limit and offset as you have done.简短的回答是文档不是最新的,最好的解决方案是像你所做的那样用限制和偏移量自己实现分页。 There is work underway to remedy this in https://jira.spring.io/browse/DATACOUCH-588 (it's not described there, but that's the tracking issue)https://jira.spring.io/browse/DATACOUCH-588中正在进行补救工作(那里没有描述,但这是跟踪问题)

Even so, a more efficient way of paging is key-set pagination ( https://use-the-index-luke.com/no-offset ) - but you'll need to implement that in your application.即便如此,一种更有效的分页方式是键集分页 ( https://use-the-index-luke.com/no-offset ) - 但您需要在您的应用程序中实现它。 It uses the indexes to get the items beginning with the first one required, instead of “skipping” over the ones in prior pages.它使用索引从所需的第一个项目开始获取项目,而不是“跳过”前面页面中的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 执行 findAll() 时 Spring boot 和 couchbase 中的 InvalidDataAccessResourceUsageException - InvalidDataAccessResourceUsageException in Spring boot and couchbase when doing findAll() 如何在响应式 Spring Data 中应用分页? - How apply pagination in reactive Spring Data? 记录来自反应式沙发库存储库的 Spring 数据查询 - Log Spring Data queries from reactive couchbase repository Spring 引导搜索过滤器和分页 - Spring boot search filter and pagination 在Couchbase中调用删除文档(带分页)时的Spring数据“TimeoutException” - Spring Data “TimeoutException” when calling delete documents (with pagination) in Couchbase Spring-boot Couchbase 通过属性抛出 IndexOutOfBoundsException 过滤器 - Spring-boot Couchbase filter by attribute throwing IndexOutOfBoundsException 如何在 spring boot 应用程序中自动恢复 Couchbase 数据库连接? - How to restore Couchbase database connection automatically in spring boot application? 为什么我的 Redis 缓存不能在我的 Spring-Boot/Spring-Data 应用程序中工作? - Why isn't my Redis cache working in my Spring-Boot/Spring-Data application? 防止由于Couchbase连接错误而导致Spring Boot启动失败 - Prevent Spring Boot startup failure on couchbase connection error Spring 数据 Mongodb 反应式存储库中 findAll 方法的分页 - Pagination for a findAll method in Spring Data Mongodb Reactive repositories
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM