Featured Article

Spring Boot Tutorial CRUD: Build Your First App in 10 Minutes

Kenneth Jul 13, 2026

Welcome to this comprehensive guide on creating a Spring Boot CRUD API. We'll walk you through the process of setting up a basic Spring Boot project and implementing the four fundamental operations of any database: Create, Read, Update, and Delete. By the end of this tutorial, you'll have a solid understanding of how to build a simple yet powerful CRUD API using Spring Boot.

Spring Boot Tutorial for Beginners 9 - Spring Boot CRUD Operations using Apache Derby
Spring Boot Tutorial for Beginners 9 - Spring Boot CRUD Operations using Apache Derby

Before we dive in, make sure you have Java Development Kit (JDK) version 8 or later installed, as well as Apache Maven for project build automation. We'll also assume you're familiar with basic Java and SQL concepts.

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

Setting Up Your Spring Boot Project

First, let's create a new Spring Boot project using Spring Initializr (https://start.spring.io/). For this tutorial, we'll choose "Spring Web" and "MySQL Driver" as our dependencies. After downloading the project, extract it and navigate to the project directory in your favorite IDE.

Master Exception Handling in Spring Boot with ControllerAdvice | Unlock Spring Boot CRUD Secrets
Master Exception Handling in Spring Boot with ControllerAdvice | Unlock Spring Boot CRUD Secrets

Next, configure your MySQL database in the application.properties file:

``` spring.datasource.url=jdbc:mysql://localhost:3306/your_database?useSSL=false&serverTimezone=UTC spring.datasource.username=your_username spring.datasource.password=your_password spring.jpa.hibernate.ddl-auto=update ```

Creating the User Entity

Spring Boot MongoDB CRUD Example
Spring Boot MongoDB CRUD Example

Let's create a simple User entity with fields like id, name, and email. Below is a basic User.java file:

```java @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; private String email; // Getters and setters } ```

To ensure automatic conversion between Java and SQL types, Spring Data JPA provides annotations like @Entity, @Id, and @GeneratedValue.

Creating the User Repository

Master CRUD Operations: Spring Boot and Spring Data JPA Unleashed
Master CRUD Operations: Spring Boot and Spring Data JPA Unleashed

Now, let's create a UserRepository interface that extends JpaRepository. This repository will interact with our User entity:

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

Implementing the CRUD Operations

Now that our setup is complete, let's dive into the CRUD operations. We'll create a simple REST controller called UserController.

Spring Boot Tutorial 22 - CRUD Operations with JPA Repository
Spring Boot Tutorial 22 - CRUD Operations with JPA Repository

Creating a New User (Create)

To create a new user, add the following method to your UserController class:

How To Develop REST CRUD API Using Spring Boot ? - JavaTechOnline
How To Develop REST CRUD API Using Spring Boot ? - JavaTechOnline
Java Spring Boot
Java Spring Boot
Complete spring boot mastery: Hands on development Bootcamp
Complete spring boot mastery: Hands on development Bootcamp
Retrieving Employee Records: Spring Boot, JdbcTemplate, and Layered Architecture
Retrieving Employee Records: Spring Boot, JdbcTemplate, and Layered Architecture
Master Exception Handling in Spring Boot with ControllerAdvice | Unlock Spring Boot CRUD Secrets
Master Exception Handling in Spring Boot with ControllerAdvice | Unlock Spring Boot CRUD Secrets
Spring Boot cheatsheet - Masterspringboot
Spring Boot cheatsheet - Masterspringboot
Spring Boot CRUD and JPA: Your Ultimate Book Example Guide
Spring Boot CRUD and JPA: Your Ultimate Book Example Guide
an image of some logos on a computer screen
an image of some logos on a computer screen
Master CRUD Operations: Spring Boot and Spring Data JPA Unleashed
Master CRUD Operations: Spring Boot and Spring Data JPA Unleashed

```java @PostMapping("/users") public ResponseEntity create(@RequestBody User user) { User savedUser = userRepository.save(user); return new ResponseEntity<>(savedUser, HttpStatus.CREATED); } ```

The @PostMapping annotation maps this method to the POST HTTP method, and @RequestBody extracts the JSON payload from the request body.

Reading All Users (Read)

To fetch all users, add the following method to your UserController class:

```java @GetMapping("/users") public List readAll() { return userRepository.findAll(); } ```

The @GetMapping annotation maps this method to the GET HTTP method.

Updating a User (Update)

To update a user, add the following method to your UserController class:

```java @PutMapping("/users/{id}") public ResponseEntity update(@PathVariable Long id, @RequestBody User updatedUser) { return userRepository.findById(id).map(user -> { user.setName(updatedUser.getName()); user.setEmail(updatedUser.getEmail()); User updated = userRepository.save(user); return ResponseEntity.ok().body(updated); }).orElse(ResponseEntity.notFound().build()); } ```

The @PutMapping annotation maps this method to the PUT HTTP method, and @PathVariable extracts the ID from the URL.

Deleting a User (Delete)

To delete a user, add the following method to your UserController class:

```java @DeleteMapping("/users/{id}") public ResponseEntity delete(@PathVariable Long id) { return userRepository.findById(id).map(user -> { userRepository.delete(user); return ResponseEntity.ok().build(); }).orElse(ResponseEntity.notFound().build()); } ```

The @DeleteMapping annotation maps this method to the DELETE HTTP method.

There you have it! You've just created a simple yet powerful CRUD API using Spring Boot. This API can be tested using tools like Postman or curl. Now that you understand the basics, explore more features and improve your API's performance and security.