问题
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?
回答1:
If you are using spring data MongoDb then you could easily achieve it through MongoDB repositories
For example, accessing the second page of User by a page size of 20 you could simply do something like this:
PagingAndSortingRepository repository = // … get access to a bean
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 Custom Query with pageable
Hope these documentation solve your problem.
来源:https://stackoverflow.com/questions/59396901/keysetseek-pagination-in-spring-data-mongodb