I have a List
of entities.
How do I convert it to Page
Object using Spring MVC 4 and Spring Data JPA?
I think you will need to fetch the correct page content as well.
PageRequest pageRequest = PageRequest.of(offset, limit);
List products = getProducts();
int total = products.size();
int start = toIntExact(pageRequest.getOffset());
int end = Math.min((start + pageRequest.getPageSize()), total);
List output = new ArrayList<>();
if (start <= end) {
output = products.subList(start, end);
}
return new PageImpl<>(
output,
pageRequest,
total
);