0

I am making a springboot pagination however :

repo.findAll (PageRequest.of (page, size) );

Doesn't seem to work.

Does anybody know the new way to paginate in spring boot 2+ after PageRequest(...) is deprecated?

Thanks in advance.

Neo Sono
  • 186
  • 1
  • 4
  • 18
  • Please have a look at this post: https://stackoverflow.com/questions/44848653/pagerequest-constructors-have-been-deprecated – AlexLiesenfeld Jul 20 '18 at 09:35

2 Answers2

0

You need a Pageable object. Sample snippet:

@Repository
public interface MyRepo extends JpaRepository<MyDto, Long> {

  Page<MyEntity> findAll(Pageable page); 

}

`If you get the Pageable object from the controller, just pass it on or else if you want to manually construct, you can do like follows:

@Test
public void testPagination(){
 assertNotNull(myRepo.findAll(PageRequest.of(0, 20)));
}

This works for me! Make sure you return Page<MyEntity> instead of List?

Karthik R
  • 5,523
  • 2
  • 18
  • 30
0

My mistake : repo.findAll (PageRequest.of (page, size) ); ... is a working methodology. Thanks for your tme @karthik R

Neo Sono
  • 186
  • 1
  • 4
  • 18