convert List<User> users to Page<User> in spring data mongo Pagination
See original GitHub issueI 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>. Please help me.
Issue Analytics
- State:
- Created 8 years ago
- Comments:18 (7 by maintainers)
Top Results From Across the Web
Convert List to Page in spring data mongo? - Stack Overflow
It very simple implementation and works fine for me. Page<User> usersPage = new PageImpl<User>(users,pageable, users.size());.
Read more >Mongodb – 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 ;.
Read more >[Solved]-Convert List to Page in spring data mongo?-mongodb
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()) ...
Read more >Paging with Spring Boot - Reflectoring
An in-depth look at the paging support provided by Spring Data for querying Spring Web MVC controllers and Spring Data repositories.
Read more >Spring Boot MongoDB Pagination example with Spring Data
findAll(Pageable pageable) : returns a Page of entities meeting the paging condition provided by Pageable object. Spring Data also supports many ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The easiest way to do that is to simply create a page out of the existing list:
new PageImpl<Foo>(listOfFoos, new PageRequest(page, size, sort), listOfFoos.size())Hope it helps. Cheers, Eugen.I tried the suggestion above but it seems that the totalElements, totalPages values are wrong. It displays all the results…
numberOfElementsvalue is not changing… whiletotalElementsis varying.lets say the number of results is 7.
current page is 1 and size is 5… “first”: true, “last”: false, “number”: 0, “numberOfElements”: 7, “size”: 5, “totalElements”: 7, “totalPages”: 2
current page is 2 and size is 5… “first”: false, “last”: false, “number”: 1, “numberOfElements”: 7, “size”: 5, “totalElements”: 12, “totalPages”: 3
current page is 3 and size is 5… “first”: false, “last”: false, “number”: 2, “numberOfElements”: 7, “size”: 5, “totalElements”: 17, “totalPages”: 4
current page is 4 and size is 5… “first”: false, “last”: false, “number”: 3, “numberOfElements”: 7, “size”: 5, “totalElements”: 22, “totalPages”: 5
It is really acting weird. below is the code used
Thanks