Spring Data MongoDB 中的 Keyset(Seek) 分页 [英] Keyset(Seek) Pagination in Spring Data MongoDB
问题描述
目前我正在尝试实现密钥集,也就是.为 Spring Data MongoDB 寻找分页.目前我正试图通过使用提供的信息来解决这个问题 此处.不幸的是,这是一个低级实现,我希望得到某种类似于 JOOQ,因为它们似乎不支持 MongoDB.
Currently I'm trying to implement keyset, aka. seek pagination for Spring Data MongoDB. Currently I'm trying to go about this by using the information provided here. Unfortunately, this is a low-level implementation, and I was hoping to get some sort of abstraction similar to JOOQ, as they don't seem to support MongoDB.
是否有任何抽象/简单的方法可以让我完成这项任务,或者这是我需要自己在低级别实现的东西?
Is there any abstractions/easy ways out there that would allow me to accomplish this task, or is this something I would need to implement on a low-level on my own?
推荐答案
如果你使用的是 Spring Data MongoDb 那么你可以通过 MongoDB 存储库
If you are using spring data MongoDb then you could easily achieve it through MongoDB repositories
例如,以 20 的页面大小访问 User 的第二页,您可以简单地执行以下操作:
For example, accessing the second page of User by a page size of 20 you could simply do something like this:
PagingAndSortingRepository repository =//... 访问 bean
PagingAndSortingRepository repository = // … get access to a bean
页面用户 = repository.findAll(new PageRequest(1, 20));
Page users = repository.findAll(new PageRequest(1, 20));
更多详细信息,请阅读以下官方文档:
For more details, please go through the below official documentation:
- https://docs.spring.io/spring-data/data-mongo/docs/1.5.0.RELEASE/reference/html/repositories.html
- https://docs.spring.io/spring-data/mongodb/docs/1.3.3.RELEASE/reference/html/mongo.repositories.html
- 带有可分页的 Spring 自定义查询
希望这些文档能解决您的问题.
Hope these documentation solve your problem.
这篇关于Spring Data MongoDB 中的 Keyset(Seek) 分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!