Featured Article

Spring Boot Tutorial CRUD Example Step by Step Guide

Kenneth Jul 13, 2026

Spring Boot, a beloved Java framework, simplifies application development by providing out-of-the-box features. One common task when building applications is implementing basic CRUD (Create, Read, Update, Delete) operations. This Spring Boot tutorial will guide you through creating a simple CRUD example using Spring Boot, Spring Data JPA, and a relational database.

Spring Boot + MySQL Database example (CRUD) in Java [Tutorial]
Spring Boot + MySQL Database example (CRUD) in Java [Tutorial]

Before we dive into the code, ensure you have Java 8 or later, Apache Maven, and an IDE like IntelliJ or Eclipse installed. Also, make sure you have a database driver for your chosen relational database (e.g., MySQL, PostgreSQL) in your system's classpath.

How To Develop REST CRUD API Using Spring Boot ? - JavaTechOnline
How To Develop REST CRUD API Using Spring Boot ? - JavaTechOnline

Setting Up the Project

First, let's set up a new Spring Boot project using start.spring.io or your preferred IDE with the following dependencies: Web, JPA, and your chosen database driver.

Spring Boot MongoDB CRUD Example
Spring Boot MongoDB CRUD Example

The generated project structure should include a main application class (e.g., Application.java) with the Spring Boot annotations like @SpringBootApplication, @EntityScan, and @EnableAutoConfiguration.

Data Model

Spring Boot + Vue.js example | Spring Data MongoDB + RestApi CRUD
Spring Boot + Vue.js example | Spring Data MongoDB + RestApi CRUD

Define a simple model class, e.g., Employee.java, to represent the data you want to perform CRUD operations on. Use annotations like @Entity, @Column, and @GeneratedValue to map the class to a database table.

```java @Entity public class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false) private String name; // other employee properties... } ```

Repository

Spring Boot RESTful CRUD Example with MySQL Database - Websparrow
Spring Boot RESTful CRUD Example with MySQL Database - Websparrow

Create a repository interface, e.g., EmployeeRepository.java, that extends JpaRepository or PagingAndSortingRepository. This interface provides basic CRUD functionality out-of-the-box.

```java public interface EmployeeRepository extends JpaRepository { } ```

Implementing CRUD Operations

CRUD with React Js and Spring Boot
CRUD with React Js and Spring Boot

Now, let's create a controller class, e.g., EmployeeController.java, that will handle the HTTP requests for creating, reading, updating, and deleting employees.

```java @RestController @RequestMapping("/api/employees") public class EmployeeController { @Autowired private EmployeeRepository employeeRepository; // POST /api/employees - Create employee @PostMapping public ResponseEntity create(@RequestBody Employee employee) { Employee savedEmployee = employeeRepository.save(employee); return new ResponseEntity<>(savedEmployee, HttpStatus.CREATED); } // GET /api/employees - Read all employees @GetMapping public List readAll() { return employeeRepository.findAll(); } // PUT /api/employees/{id} - Update employee @PutMapping("/{id}") public ResponseEntity update(@PathVariable Long id, @RequestBody Employee employee) { if (employeeRepository.existsById(id)) { employee.setId(id); Employee updatedEmployee = employeeRepository.save(employee); return new ResponseEntity<>(updatedEmployee, HttpStatus.OK); } else { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } // DELETE /api/employees/{id} - Delete employee @DeleteMapping("/{id}") public ResponseEntity delete(@PathVariable Long id) { if (employeeRepository.existsById(id)) { employeeRepository.deleteById(id); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } else { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } } ```

Master CRUD Operations: Spring Boot and Spring Data JPA Unleashed
Master CRUD Operations: Spring Boot and Spring Data JPA Unleashed
Spring Boot CRUD and JPA: Your Ultimate Book Example Guide
Spring Boot CRUD and JPA: Your Ultimate Book Example Guide
How To Develop REST API Using Spring Boot ?
How To Develop REST API Using Spring Boot ?
Spring Boot + Kotlin + AngularJS + WebJar CRUD Example Part 2 » Tell Me How - A Place for Technology Geekier
Spring Boot + Kotlin + AngularJS + WebJar CRUD Example Part 2 » Tell Me How - A Place for Technology Geekier
Spring Restful Web Services JSON CRUD Example - Dinesh on Java
Spring Restful Web Services JSON CRUD Example - Dinesh on Java
Spring Boot Security OAuth2 Example
Spring Boot Security OAuth2 Example
Unlocking JSON in Restful Web Services: Spring Boot, JPA & Jersey Explained!
Unlocking JSON in Restful Web Services: Spring Boot, JPA & Jersey Explained!
Couture
Couture
Building your first REST API: Java and Spring Boot
Building your first REST API: Java and Spring Boot

Testing the API

You can now test your API using tools like Postman, curl, or create a simple Java client to perform CRUD operations on your Spring Boot application.

To create a Java client, you can use the resttemplateexchange method of the TestRestTemplate class from Spring's testing framework. Here's an example:

Now that you've seen how to create a simple Spring Boot CRUD example, you can build upon this foundation to create more complex applications. Explore Spring Boot's extensive feature set, such as microservices, security, and externalized configuration, to continuously enhance your development experience.