Paging with Spring Framework

1

I have a question, need to make a paging when I return all the records in a table, I do not have much experience with Spring and I would like to know how to do it, do I need to override findAll ()? Or in the controller's own method already it is possible to do? Thanks in advance.

    
asked by anonymous 09.06.2016 / 13:46

2 answers

2

If you are using Spring Data you can create a interface that extends to interface PagingAndSortingRepository that contains additional methods for paging.

The method findAll" receives an object of type Pageable , which contains the criteria for paging, such as quantity of items, current page, which field you want to sort, and whether the sort is ascending or descending.

See an example:

Interface: TheLongparameteristhetypeoftheUserId

Controller:

tamanhoistheamountofitemsyoushouldhaveonthepage.The findAll" returns an object of type Page that contains the information of the current page: Contents, Quantity, Total Elements, Number of Pages. You can check the documentation which is returned by the

    
09.06.2016 / 14:48
1

By what you said it seems to me that you use Spring Data, so Spring itself provides another interface that you can extend when you are declaring your repository, this being the PagingAndSortingRepository, so your findAll receives an object of type Pageable and the return of the findAll method automatically comes out paged, I'll pass you some reference links, anything I'm here and you can ask.

Doc interface.
link

Doc how to use.
link

    
09.06.2016 / 14:10