angular-spring-boot-crud-example-feature-image

Angular 8 + Spring Boot example: Build a CRUD App

In this tutorial, we will learn how to build a full stack Angular 8 + Spring Boot example with a CRUD App. The back-end server uses Spring Boot with Spring Web MVC for REST Controller and Spring Data JPA for interacting with MySQL/PostgreSQL database. Front-end side is made with Angular 8, HTTPClient & Router.

More Practice:
Angular 8 + Spring Boot: JWT Authentication with Spring Security example
Angular 8 + Spring Boot + MongoDB example: CRUD App
Angular 8 + Spring Boot: File upload example


Angular 8 & Spring Boot CRUD example

We will build a full-stack Tutorial Application in that:

  • Each Tutorial has id, title, description, published status.
  • We can create, retrieve, update, delete Tutorials.
  • We can also find Tutorials by title.

The images below shows screenshots of our System.

– Add Tutorial:

angular-crud-app-create

– Retrieve all Tutorials:

angular-crud-app-retrieve-all

– Click on Edit button to update a Tutorial:

angular-crud-app-update

On this Page, you can:

  • change status to Published using Publish button
  • delete the Tutorial using Delete button
  • update the Tutorial details with Update button

– Search Tutorials by title:

angular-crud-app-search

Angular 8 & Spring Boot Architecture

This is the application architecture we will build:

angular-spring-boot-jpa-crud-example-architecture

– Spring Boot exports REST Apis using Spring Web MVC & interacts with Database using Spring JPA
– Angular Client sends HTTP Requests and retrieve HTTP Responses using axios, shows data on the components. We also use Angular Router for navigating to pages.
– Database could be MySQL or PostgreSQL.

Spring Boot Back-end

Overview

These are APIs that Spring Boot App will export:

MethodsUrlsActions
POST/api/tutorialscreate new Tutorial
GET/api/tutorialsretrieve all Tutorials
GET/api/tutorials/:idretrieve a Tutorial by :id
PUT/api/tutorials/:idupdate a Tutorial by :id
DELETE/api/tutorials/:iddelete a Tutorial by :id
DELETE/api/tutorialsdelete all Tutorials
GET/api/tutorials?title=[keyword]find all Tutorials which title contains keyword

– We make CRUD operations & finder methods with Spring Data JPA’s JpaRepository.
– The database could be PostgreSQL or MySQL depending on the way we configure project dependency & datasource.

Technology

  • Java 8
  • Spring Boot 2.2.1 (with Spring Web MVC, Spring Data JPA)
  • PostgreSQL/MySQL
  • Maven 3.6.1

Project Structure

angular-spring-boot-crud-example-spring-server-project-structure

Tutorial data model class corresponds to entity and table tutorials.
TutorialRepository is an interface that extends JpaRepository for CRUD methods and custom finder methods. It will be autowired in TutorialController.
TutorialController is a RestController which has request mapping methods for RESTful requests such as: getAllTutorials, createTutorial, updateTutorial, deleteTutorial, findByPublished
– Configuration for Spring Datasource, JPA & Hibernate in application.properties.
pom.xml contains dependencies for Spring Boot and MySQL/PostgreSQL.

Implementation

You can find step by step to implement this Spring Boot Server Application in the post:
Spring Boot, Spring Data JPA – Building Rest CRUD API example

Angular 8 Front-end

Overview

angular-node-express-mysql-crud-example-front-end-overview

– The App component is a container with router-outlet. It has navbar that links to routes paths via routerLink.

TutorialsList component gets and displays Tutorials.
Tutorial component has form for editing Tutorial’s details based on :id.
AddTutorial component has form for submission new Tutorial.

– These Components call TutorialService methods which use Angular HTTPClient to make HTTP requests and receive responses.

Technology

  • Angular 8
  • Angular HTTPClient
  • Angular Router

Project Structure

angular-node-js-express-sequelize-mysql-example-angular-project-structure

– There are 3 components: tutorials-list, tutorial-details, add-tutorial.
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.

Implementation

You can find step by step to implement this Angular App in the post:
Angular 8 CRUD Application example with Web API

Conclusion

Now we have an overview of Angular 8 + Spring Boot CRUD example when building a CRUD App.

We also take a look at client-server architecture for REST API using Spring Web MVC & Spring Data JPA, 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:

Happy learning, see you again!

Further Reading

Leave a Reply

Your email address will not be published. Required fields are marked *