Convert list to page in spring mongo data?

I'm really trying to convert List<User> usersto Page<User>in the spring data mongo? Note Pageis the API from org.springframework.data.domain.Page;

I use Paginationfrom Spring Data Mongo, so I need to send Page<User>, not List<User>.

How can we get pages from a list if I don't want to use the repository method Page<>?

Please help me.

+4
source share
1 answer

You can do it as follows. This is a very simple implementation and works great for me.

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

Source: https://habr.com/ru/post/1607353/


All Articles