In this tutorial, I will continue to make Server side Pagination and Filter with Spring Data JPA and Pageable
.
Full Article: https://bezkoder.com/spring-boot-pagination-filter-jpa-pageable/
For MongoDB database:
Spring Boot MongoDB Pagination & Filter example with Spring Data
Assume that we have tutorials table in database like this:
Here are some url samples for pagination (with/without filter):
/api/tutorials?page=1&size=5
/api/tutorials?size=5
: using default value for page/api/tutorials?title=data&page=1&size=3
: pagination & filter by title containing 'data'/api/tutorials/published?page=2
: pagination & filter by 'published' statusThis is structure of the Server side pagination result that we want to get from the APIs:
{
"totalItems": 8,
"tutorials": [...],
"totalPages": 3,
"currentPage": 1
}
Read Tutorials with default page index (0) and page size (3):
Indicate page index = 2 but not specify size (default: 3) for total 8 items:
Indicate size = 5 but not specify page index (default: 0):
For page index = 1 and page size = 5 (in total 8 items):
Pagination and filter by title that contains a string:
Pagination and filter by published status:
For more details, implementation and source code, please visit:
https://bezkoder.com/spring-boot-pagination-filter-jpa-pageable/
To bring pagination and sorting together, please visit:
Spring Boot Pagination and Sorting example
Handle Exception for this Rest APIs is necessary:
Spring Boot @ControllerAdvice & @ExceptionHandler example
You can also know how to deploy this Spring Boot App on AWS (for free) with this tutorial.
React Pagination Client that works with this Server:
React Pagination with API using Material-UI
Angular Client working with this server:
Or Vue Client:
Happy learning! See you again.
#spring #spring-boot #pagination #spring-data #web-development #java