In this tutorial, I will show you how to build a full-stack Pagination (Angular 8 + Spring Boot) example on Server side. The back-end server uses Spring Data and Spring Web for REST APIs, front-end side is an Angular 8 App with HTTPClient.
Pagination with Angular 8 & Spring Boot example
Assume that we have tutorials table in database like this:
We need to export APIs for pagination (with/without filter) as following samples:
/api/tutorials?size=5: using default value for page
/api/tutorials?title=data&page=1&size=5: pagination & filter by title containing ‘data’
/api/tutorials/published?page=2: pagination & filter by ‘published’ status
This is structure of the result that we want to get from the APIs:
Our Angular app will display the result with pagination:
You can change to a page with larger index:
Or change page size (quantity of items per page):
Or paging with filter:
We’re gonna build the application with following architecture:
– Spring Boot exports REST Apis using Spring Web MVC & interacts with Database using Spring Data.
– Angular 8 Client sends HTTP Requests and retrieve HTTP Responses using axios, shows data on the components. We also use Angular Router for navigating to pages.
Spring Boot Server side Pagination
The Spring Boot Server will be built with Spring Web and Spring Data.
It can export API with endpoint that supports both pagination and filter:
The response structure looks like this:
"title": "Microservices Tut#6",
"description": "Tut#6 Description",
"title": "MongoDB Database Tut#7",
"description": "Tut#7 Description",
"title": "MySQL Database Tut#8",
"description": "Tut#8 Description",
This is the structure of the project that we’re gonna build:
Let me explain it briefly.
Tutorial data model class corresponds to entity/document and table/collection tutorials.
TutorialRepository is an interface for CRUD methods and custom finder methods. It will be autowired in
TutorialController is a RestController which has request mapping methods for RESTful requests such as: getAllTutorials, createTutorial, updateTutorial, deleteTutorial, findByPublished…
– Configuration for Spring Datasource, DB Connection in application.properties.
– pom.xml contains dependencies for Spring Boot and MySQL/PostgreSQL/MongoDB.
Step by step to make the Server side Pagination back-end for this Angular front-end can be found at one of following posts:
– For MySQL/PostgreSQL: Spring Boot Pagination & Filter example | Spring JPA, Pageable
– For MongoDB: Spring Boot MongoDB Pagination example with Spring Data
Angular Pagination Client
App component is a container with
router-outlet. It has navbar that links to routes paths via
TutorialsList component gets and displays Tutorials with pagination and filter.
Tutorial component has form for editing Tutorial’s details based on
AddTutorial component has form for submission new Tutorial.
– These Components call
TutorialService methods which use Angular
HTTPClient to make HTTP requests and receive responses.
Now here is the directory of our Angular Client:
– There are 3 components:
tutorial.service has methods for sending HTTP requests to the Apis.
– app-routing.module.ts defines routes for each component.
app component contains router view and navigation bar.
app.module.ts declares Angular components and import necessary modules.
Step by step to build front-end application for the Server side pagination back-end above can be found at:
Angular 8 Pagination example using ngx-pagination
Newer version: Angular 10 Pagination example using ngx-pagination
Now we have an overview of Server side Pagination example for Angular 8 + Spring Boot when building a full-stack App.
We also take a look at client-server architecture for REST API using Spring Boot with Spring Data, as well as Angular 8 project structure for building a front-end app to make HTTP requests and consume responses.
Next tutorials show you more details about how to implement the system:
You may want to know how to run both projects in one place:
How to Integrate Angular with Spring Boot Rest API
Happy learning, see you again!
Originally published at https://bezkoder.com.