Add Dependencies to build.gradle file

Add the following dependencies to build.gradle file if not already present.

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.projectlombok:lombok:1.18.20'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

Spring MVC CRUD with Example

CRUD stands for Create, Read/Retrieve, Update, and Delete. These are the four basic operations to create any type of project. Spring MVC is a Web MVC Framework for building web applications. It is a spring module same as Spring boot, spring-security, etc. The term MVC stands for Model-View-Controller architecture. In this article, we will be building a simple course-tracking CRUD application that will be focused on the Spring MVC module.

Similar Reads

CRUD Example of Spring MVC

Project Structure...

1. Add Dependencies to build.gradle file

Add the following dependencies to build.gradle file if not already present....

2. Model Layer

Create a simple POJO (Plain old java object) with some JPA and Lombok annotations....

3. DAO (Data access object) / Repository Layer

...

4. Service Layer

@Repository: This annotation is a stereotype that marks the repository class. It indicates that the annotated class acts as a database on which CRUD operations can take place. JpaRepository : JpaRepository is a JPA-specific extension of the Repository. It contains the full API of CrudRepository and PagingAndSortingRepository. So it contains API for basic CRUD operations and also API for pagination and sorting. Here we enable database operations for Employees. To learn more about spring data Jpa, refer this article....

5. Controller Layer

...

HTML Templates

The service layer provides an abstraction over the data layer. Its main purpose is to fulfill business requirements. It is always better to separate business logic from app logic....

CRUD Operations

...

Contact Us