Using Pagination

Why do we need pagination?

We currently load all users from the database in one big table and present that. To avoid overloading the database, we should implement pagination. That will let us get users in batches of ten or twenty users, for example. This allows us to specify the number of users to retrieve in one query and display it on a single page.

Pagination in Spring

Spring Data JPA makes it very easy to implement pagination. We need to change our UserRepository to extend PagingAndSortingRepository as opposed to CrudRepository:

Get hands-on with 1000+ tech skills courses.