用mongoTemplate分页 [英] Pagination with mongoTemplate

查看:2340
本文介绍了用mongoTemplate分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可查询的查询:

I have a Query with Pageable:

Query query = new Query().with(new PageRequests(page, size))

如何使用MongoTemplate执行它?我没有看到一个方法返回 Page< T>

How can I execute it with MongoTemplate ? I don't see a single method returning Page<T>.

推荐答案

MongoTemplate 没有返回 Page 的方法。 find()方法返回一个普通的列表

MongoTemplate does not have methods to return Page. The find() methods return an ordinary List.

with(新的PageRequests(页面,大小)在内部用于调整 skip 限制带有MongoDB查询的(我认为是计数查询)

with(new PageRequests(page, size) is used internally to adjust skip and limit with a MongoDB query (proceeded by a count query I think)

Page can与 MongoDB存储库这是Spring数据存储库的一个特例。

Page can be used in conjunction with MongoDB repositories which is a specialized case of Spring data repositories.

因此,你必须使用 MongoRepository 's 页面findAll(可分页可分页)用于分页结果(实际上继承自 PagingAndSortingRepository )。

Thus, you'll have to use MongoRepository's Page findAll(Pageable pageable) for paginated results (actually inherited from PagingAndSortingRepository).

这篇关于用mongoTemplate分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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