Spring Data Repository Interface

Spring Boot – CRUD Operations

CRUD stands for Create, Read/Retrieve, Update, and Delete and these are the four basic operations that we perform on persistence storage. CRUD is data-oriented and the standardized use of HTTP methods or there is a term for this called HTTP action verbs. HTTP has a few action verbs or methods that work as CRUD operations and do note they are vital from a developmental point perspective in programming that also helps us relate better web development and also aids us while dealing with databases. In this article, we will be discussing the CRUD operations in Spring Boot, before that let us understand what are standard CRUD Operations:

  • POST: Creates a new resource
  • GET: Reads/Retrieve a resource
  • PUT: Updates an existing resource
  • DELETE: Deletes a resource

As the name suggests, 

  • CREATE Operation: Performs the INSERT statement to create a new record.
  • READ Operation: Reads table records based on the input parameter.
  • UPDATE Operation: Executes an update statement on the table. It is based on the input parameter.
  • DELETE Operation: Deletes a specified row in the table. It is also based on the input parameter.

So in this article, we are going to perform some basic CRUD Operations by creating a Spring Boot Application and using the H2 Database. So, here is a brief explanation of What’s Spring Boot and What’s H2 Database. 

Similar Reads

Spring Boot

Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because it’s a rapid production-ready environment that enables the developers to directly focus on the logic instead of struggling with the configuration and setup. Spring Boot is a microservice-based framework and making a production-ready application in it takes very little time....

H2 Database

H2 is a relational database management system written in Java. It can be embedded in Java applications or run in client-server mode. The main features of H2 are:...

Spring Boot CrudRepository

There is an interface available in Spring Boot named as CrudRepository that contains methods for CRUD operations. It provides generic Crud operation on a repository. It is defined in the package org.springframework.data.repository and It extends the Spring Data Repository interface. If someone wants to use CrudRepository in the spring boot application he/she has to create an interface and extend the CrudRepository interface....

Spring Boot JpaRepository

JPA stands for Java Persistence API. It is a specific extension of repository. JpaRepository defined in the package org.springframework.data.jpa.repository. It provides Jpa related methods such as flushing the persistence context and deleting records in a batch. JpaRepository contains APIs for basic CRUD operations, pagination and sorting. By using JpaRepository, we do not need to write DDL/DML queries instead we can use XML/annotations....

Spring Data Repository Interface

...

Difference between CRUD Repository and Jpa Repository

CRUD Repository JPA Repository CRUD Repository extends Repository interface JpaRepository extends PagingAndSortingRepository. It performs all CRUD operations. It has methods such as save(), saveAll(), findById(), findAll() etc. It contains API of CrudRepository and PagingandSortingRepository. It has methods such as flush(), saveAllAndFlush(), deleteInBatch() etc. CrudRepository works as a base interface. JpaRepository extends both CrudRepository and PagingAndSortingRepository. Syntax: public interface CrudRepository extends Repository Syntax: public interface JpaRepository extends PagingAndSortingRepository, QueryByExampleExecutor...

Example of Spring Boot – CRUD Operations

Step 1: Refer to this article How to Create a Spring Boot Project with IntelliJ IDEA and create a Spring Boot project....

Testing the Endpoint in Postman

...