Search code examples
mongodbspring-data-mongodbspring-mvc-test

Convert List to Page in spring data mongo?


I am really struggling to convert List<User> users to Page<User> in spring data mongo? Note Page is an API from org.springframework.data.domain.Page;

I am using Pagination of Spring Data Mongo, so I need to sent Page<User> and not the List<User> .

How we can get Pages from List if I don't want to use Page<> repository method?

Please help me.


Solution

  • You can do it in following way. It very simple implementation and works fine for me.

    Page<User> usersPage = new PageImpl<User>(users,pageable, users.size());