Reactjs + Spring Boot CRUD Full Stack Application – Spring Boot Backend

Hey guys in this post, we will create Spring boot backend project, we will create REST API that communicate with MySQL database and we will perform the database operations such as Create, Read, Update and Delete.

Read Next: Reactjs + Spring Boot CRUD Full Stack Application – Create React application

Read More:

Create spring boot project

There are many different ways to create a spring boot application, you can follow the below articles to create one –

>> Create spring boot application using Spring initializer
>> Create spring boot application in Spring tool suite [STS]
>> Create spring boot application in IntelliJ IDEA

Add maven dependencies

Open pom.xml and add the following dependencies –

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
		<relativePath/> <!-- lookup parent from repository -->
	<description>Spring boot rest api</description>



  • spring-boot-starter-web dependency for building web applications using Spring MVC.
  • It uses the tomcat as the default embedded container.
  • spring-boot-devtools dependency for automatic reloads or live reload of applications.
  • spring-boot-starter-data-jpa dependency for performing database operations.

  • lombok dependency is a java library that will reduce the boilerplate code that we usually write inside every entity class like setters, getters, and toString().
  • mysql-connector-java dependency is to store the data into the database.

Create Database

Open MySQL workbench and execute the following statements-

CREATE DATABASE employeeportal;

USE employeeportal;

CREATE TABLE tbl_employees
    name VARCHAR(255) NOT NULL,
    location VARCHAR(255) NOT NULL,
    department VARCHAR(255) NOT NULL

INSERT INTO tbl_employees(name, location, department) 
VALUES("Bushan", "India", "IT");

INSERT INTO tbl_employees(name, location, department) 
VALUES("Bharath", "Australia", "Marketing");

Configure Datasource

Open file and add the following content.



Note: change spring.datasource.username and spring.datasource.password as per your MySQL database installation.

Create an Entity class

Create class inside in.bushansirgur.springbootrestapi.entity package and add the following content

package in.bushansirgur.springbootrestapi.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Table(name = "tbl_employees")
public class Employee {
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	private String name;
	private String location;
	private String department;
  • All your domain models must be annotated with @Entity annotation. It is used to mark the class as a persistent Java class.
  • @Table annotation is used to provide the details of the table that this entity will be mapped to.
  • @Id annotation is used to define the primary key.
  • @GeneratedValue annotation is used to define the primary key generation strategy.
  • @Column annotation is used to define the properties of the column that will be mapped to the annotated field.

Create a Repository

Create interface inside in.bushansirgur.springbootrestapi.repository package and add the following content

package in.bushansirgur.springbootrestapi.repository;

import org.springframework.stereotype.Repository;

import in.bushansirgur.springbootrestapi.entity.Employee;

public interface EmployeeRepository extends JpaRepository<Employee, Long>{


Create a Controller

Create class inside in.bushansirgur.springbootrestapi.controller package and add the following content

We will create 5 REST end points that performs the basic database operations such as Create, Read, Update and Delete.

package in.bushansirgur.springbootrestapi.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import in.bushansirgur.springbootrestapi.entity.Employee;
import in.bushansirgur.springbootrestapi.repository.EmployeeRepository;

public class EmployeeController {
	private EmployeeRepository eRepo;
	public List<Employee> getAllEmployees() {
		return eRepo.findAll();
	public Employee getEmployeeById(@PathVariable Long id) {
		return eRepo.findById(id).get();
	public Employee saveEmployeeDetails(@RequestBody Employee employee) {
	public Employee updateEmployee(@RequestBody Employee employee) {
	public ResponseEntity<HttpStatus> deleteEmployeeById(@PathVariable Long id) {
		return new ResponseEntity<>(HttpStatus.NO_CONTENT);

Run the App

Run the application using the below maven command –

mvn spring-boot:run

Open the postman REST client and test the APIs

  • localhost:8080/api/v1/employees


  • localhost:8080/api/v1/employees


  • localhost:8080/api/v1/employees


  • localhost:8080/api/v1/8


What’s Next?

In the next post, we will create React application and we will consume these REST end points to build the full stack application.

Read Next: Reactjs + Spring Boot CRUD Full Stack Application – Create React application

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

This Post Has One Comment

  1. Adrian Pajaro

    Please help me

    “timestamp”: “2021-10-25T09:54:59.545+00:00”,
    “status”: 404,
    “error”: “Not Found”,
    “message”: “No message available”,
    “path”: “/api/v1/employees”

Leave a Reply