如何解决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)-但您需要在应用程序中实现它。它使用索引来获取从所需的第一个项目开始的项目,而不是“跳过”先前页面中的项目。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。