Spring Boot Pagination & Filter example | Spring JPA, Pageable

Spring Boot Pagination & Filter example | Spring JPA, Pageable

Java Spring Boot Pagination and Filter with Spring Data JPA, Spring Pageable example - Spring JPA Server side Pagination with Filter example

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

Spring Boot Pagination & Filter example overview

One of the most important things to make a website friendly is the response time, and pagination comes for this reason. For example, this bezkoder.com website has hundreds of tutorials, and we don't want to see all of them at once. Paging means displaying a small number of all, by a page.

Assume that we have tutorials table in database like this:

spring-boot-pagination-filter-example-spring-jpa-pageable-table

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' status

This 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):

spring-boot-pagination-filter-example-spring-jpa-pageable-default

Indicate page index = 2 but not specify size (default: 3) for total 8 items:

  • page_0: 3 items
  • page_1: 3 items
  • page_2: 2 items

spring-boot-pagination-filter-example-spring-jpa-pageable-page

Indicate size = 5 but not specify page index (default: 0):

spring-boot-pagination-filter-example-spring-jpa-pageable-size

For page index = 1 and page size = 5 (in total 8 items):

spring-boot-pagination-filter-example-spring-jpa-pageable-page-size

Pagination and filter by title that contains a string:

spring-boot-pagination-filter-example-spring-jpa-pageable-title

Pagination and filter by published status:

spring-boot-pagination-filter-example-spring-jpa-pageable-status

For more details, implementation and source code, please visit: https://bezkoder.com/spring-boot-pagination-filter-jpa-pageable/

Further Reading

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

Alt Text

Angular Client working with this server:

Or Vue Client:

Happy learning! See you again.

spring spring-boot pagination spring-data web-development java

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Develop Web Application with Spring Boot

Spring Boot is a popular Java-based web development framework. This tutorial help to develop the "Hello World" web application. Let’s follow the quick tutorials with the basic assumption that Java8, maven, and eclipse are installed, and the reader knows their basic usage. Let's install the Spring tools suite(STS) on Eclipse IDE to make development easier.

Wondering how to upgrade your skills in the pandemic? Here's a simple way you can do it.

Corona Virus Pandemic has brought the world to a standstill. Countries are on a major lockdown. Schools, colleges, theatres, gym, clubs, and all other public

Productive Web Development in Java with IntelliJ IDEA, Spring Boot and Vaadin

We cover tips and tricks to help you become a more productive web app developer. We build a small web app using Vaadin's Java API and Spring Boot. We show you how to set up IntelliJ IDEA to automatically reload your app and browser as you develop and cover our favorite shortcuts and hacks for productive and enjoyable web app development in Java.

Top 10 Advanced Java and Spring Boot Courses for Full-Stack Java Developers

These are best online courses to learn Spring Boot, Advanced Java, Docker, React, Microservices, DEvops, and Angular to become full stack Java developer.

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).