[英]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.