简体   繁体   English

Spring 数据 Mongodb @Query 分页

[英]Spring Data Mongodb @Query with pagination

Is there any way to write some query to mongo with @Query annotation and add paginaiton right into it.有什么方法可以使用@Query注释向 mongo 编写一些查询并将 paginaiton 添加到其中。 I have a method in repository我在存储库中有一个方法

@Query("{'customer._id' : ?0 }")
List<Order> findOrderByCustomerName(String customerName);

and i want it to looks smth like this我希望它看起来像这样

@Query("{'customer._id' : ?0 }.skip{(?1 - 1) * ?2}.limit(?2)")
List<Order> findOrderByCustomerName(String customerName, int page, int size);

Is there any way to to it?有什么办法吗?

You can add Pageable as a parameter.您可以添加Pageable作为参数。

@Query("{'customer._id' : ?0 }")
List<Order> findOrderByCustomerName(String customerName, Pageable pageable);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM