用mongoTemplate分页 [英] Pagination with 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屋!