Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringData PageImpl totalElements is wrong

Tags:

spring-data

When I new a PageImpl Object like :

new PageImpl<CompanyEntity>(content, new PageRequest(page, size), total);

the result is not correct.

When the "size" lagger than "total" the totalElements use the "content.size" and when "size" less than "total" the totalElements use the "total".

why ?

The "totalElements" shouldn't represent the total count of elements ?

Help!

like image 531
meteor Avatar asked Oct 17 '25 05:10

meteor


1 Answers

set PageRequest page start to 0. It solved my problem.

PageRequest pageRequest = PageRequest.of(pageNo-1,pageSize,sort);
    Page<T> response = new PageImpl<>(result,pageRequest,totalCount);
like image 109
Ryan Avatar answered Oct 19 '25 13:10

Ryan