Spring Boot + Angular 8 CRUD Example

Github Link: https://github.com/mehulk05/Spring-Boot-Angular-8-CRUD-Example

Mehul Kothari
Analytics Vidhya
10 min readOct 20, 2019

--

Github Link: https://github.com/mehulk05/Spring-Boot-Angular-8-CRUD-Example

Working Demo

Before Begining, I have learned and got the inspiration to write this article from Java Guides. You can refer that tutorial here

Introduction

A lot of people asking how angular can work with Spring Boot Application. Here is the tutorial in very simple language. In this article, I will show you how to develop a CRUD (create read update delete) web application using Angular 8 and Spring Boot. The application contains the Employee form which has the CRUD operations like add, view, delete, and update it. For the front end, we will use Angular and consume the service. Whereas the backend will be in spring Boot which will provide us some data

BackEnd Technology

  • SpringBoot 2
  • Hibernate 5
  • Spring Data JPA

FrontEnd Technology

  • Angular8
  • Bootstrap
  • Jquery

So We will be creating it in 5 parts

1. Creating SpringBoot project

2. Creating Rest API using Spring Boot

3. Create an Angular App

4. Creating Component, Service and Modal files in angular

5 Configuring App to run

1. Creating SpringBoot project

  • 1.1 Create a Spring project

To create a spring boot project you can go to spring Initializer. You can begin with the default settings and generate a project and then unzip it and open in any IDE(preferrable Spring tool suite or Eclipse). Below is the image you can add the following dependency

  • 1.2 Update POM.xml

Next step is you need to go to pom.xml in package structure and aa following dependencies

  • 1.3 Configure database properties

Configure your database to store values

2. Creating Rest API using Spring Boot

  • Create employee
  • Update Employee
  • Delete Employee
  • List Employee
  • Get a single employee by its id
  • 2.1 Create the entity class (Employee.java)

Here, we are creating an Entity/POJO (Plain Old Java Object) class. The code for employee.java can be found here on my repo

https://github.com/mehulk05/Spring-Boot-Angular-8-CRUD-Example/tree/master/springboot2-jpa-crud-example/src/main/java/net/guides/springboot2/springboot2jpacrudexample/model

  • 2.2 Create the DAO interface(EmployeeRepository.java)

Here, we are creating the DAO interface to perform database related operations.Below is GitHub link

  • 2.3 Create the controller class

Here, we are creating the Controller class to make communication on a different path. Below is GitHub link

https://github.com/mehulk05/Spring-Boot-Angular-8-CRUD-Example/tree/master/springboot2-jpa-crud-example/src/main/java/net/guides/springboot2/springboot2jpacrudexample/controller

  • 2.4 Handling Errors

For error handling, you can refer to my GitHub link. I am skipping that part here

3. Create an Angular App

So what we will add in angular app

Components:

  • create-employee
  • employee-list
  • employee-details

Service

  • employee-service.service.ts

Modal

  • employee.ts

To install jquery and bootstrap you can refer any external resource’

4. Creating Component, Service and Modal files in angular

4.1 Modal Class(Employee.ts)

4.2 Employee List Component(employee-list.component.ts)

Below is Github link

https://github.com/mehulk05/Spring-Boot-Angular-8-CRUD-Example/tree/master/angular8-springboot-client/src/app/employee-list

employee-component.html

4.3 Create Employe Component

In this, we will write code for creating an employee. You can find Github link here

create-employe.component.ts

create-employee.component.html

4.4 Update Employee Component

Here we will write angular code for updating component

https://github.com/mehulk05/Spring-Boot-Angular-8-CRUD-Example/tree/master/angular8-springboot-client/src/app/update-employee

update-employee.component.html

update-component.ts

4.5 Employee Detail

Here we will write angular code to show employee-detail .here is my Github link for same

employee-detail.component.html

Employe-detail.component.ts

Service

Employee service will contain all the methods and provide data to all the components. The EmployeeService will be used to fetch the data from the spring-boot local server (backend) .below is Github link for the same.

https://github.com/mehulk05/Spring-Boot-Angular-8-CRUD-Example/blob/master/angular8-springboot-client/src/app/employee.service.ts

4.7 Employee-serice.service.ts

5 Configuring App to run

Here in this section, we will be configuring app so that we can run it. First of all, we will add routing

5.1 Routing:

Routing is used to call or navigate different components in our Angular app. Below is the Github link

App.routing.modue.ts

5.2 AppComponent

App component is the app-root file which is executed in index.html.To make our component accessible we need to add some code in app.component.html.Below is the GitHub link for same

https://github.com/mehulk05/Spring-Boot-Angular-8-CRUD-Example/blob/master/angular8-springboot-client/src/app/app.component.html

app.component.html

6 Running the app and spring-boot app

Step 1: First of all run the spring boot app. Once you see the success message in the console of spring boot move to step 2

Step 2: Now run the angular app by running a command

If you find some port conflict issue you can manually specify port no

Screenshot

Employee List
Add Employee
Employee Detail

Source Code on my GitHub repository

Feel free to ask if you have any doubts. I will be grateful to help you out. If you like my blogs, Show your support at https://paypal.me/mehulk05?country.x=IN&locale.x=en_GB

--

--

Mehul Kothari
Analytics Vidhya

Mean stack and Full stack Developer. Open to work as freelancer for designing and developing websites.