如何在Couchbase中使用Spring数据进行分页和排序 [英] How can I do paging and sorting using spring data with Couchbase

查看:189
本文介绍了如何在Couchbase中使用Spring数据进行分页和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用spring-data-couchbase进行分页和排序,但似乎org.springframework.data.couchbase.repository仅具有CouchbaseRepository,该扩展了CrudRepository<T,ID>.

I am trying to do paging and sorting using spring-data-couchbase but it seems org.springframework.data.couchbase.repository has only CouchbaseRepository which is extending CrudRepository<T,ID>.

没有从PagingAndSortingRepository<T,ID>扩展的接口.

我确实为问题设置跳过和限制实现了非常规的解决方案.但是要获得页数总数,该解决方案无法使用此总数. 看来Page<T>确实有.getTotalPages()

I did implement an unconventional solution to the problem setting skip and limit. But want to get total number of page count, which is not available with this solution. It seems Page<T> does have .getTotalPages()

推荐答案

4年以来,可惜仍然没有ReactiveCouchbasePagingAndSortingRepository. 相反,我将使用索引,并选择offset参数和count的组合来解决此问题. https://docs.couchbase.com/服务器/当前/n1ql/n1ql语言参考/aggregatefun.html#countn https://docs.couchbase.com/server/当前/n1ql/n1ql-language-reference/offset.html

4 Years on, sadly still no ReactiveCouchbasePagingAndSortingRepository. Instead I will use indexes, and a combination of the offset parameter and the count select to solve this problem. https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/aggregatefun.html#countn https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/offset.html

@Query("#{#n1ql.selectEntity} where #{#n1ql.filter} ORDER BY name LIMIT $1 OFFSET $2;")
Flux<Location> findPage(int limit, int offset);

如果他们确实添加了它,它应该出现在这里(或在更高版本中)

If they do add it, it should appear here (or in a later version)

https://docs.spring.io/spring-data/couchbase/docs/4.0.x/api/index.html?org/springframework/data/couchbase/repository/package-tree .html

这篇关于如何在Couchbase中使用Spring数据进行分页和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆