1
votes

I'm trying to fetch limited amound of search result but still use of pagination. When I use next line in my repository class I get 100 result on the page.

Page<Media> findTop100ByOrderByViewCount(Pageable pageable);

If I use next line instead, then I get expected result with according to my pageable which is 10 item on each page.

 Page<Media> findAllByOrderByViewCount(Pageable pageable);

I want to limit the search result. If there are 1000s of search result, I don't want to have 100s of paginated result. I want to limit my paginated limit to have max 10 page.

How can I achieve that in Spring boot? I'm using version of 2.2.2.RELEASE.

1

1 Answers

0
votes

There is no shortcut for this in Spring Data.

You can wrap the call to the repository and replace the Page you receive with a modified one, which limits the total amount to 10*pagesize and removes the next value for page number 10. And probably skips the call to the database completely if the pagenumber is greater 10.