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.
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.
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'
2. Model Layer
Create a simple POJO (Plain old java object) with some JPA and Lombok annotations.
- @NoArgsConstructor – This annotation generates constructors with no arguments.
- @AllArgsConstructor – This annotation generates constructors with all field arguments.
- @Data – This annotation generates getters, setter, toString, required argument constructors, equals & hashCode.
- @Entity – This annotation defines that a class can be mapped to a table.
- @Table – This annotation specifies the name of the database table used for mapping.
- @Id – This annotation marks the primary key for the entity.
- @GeneratedValue – This annotation provides the specification of generation strategies for the values of the primary keys.
- @Column – This annotation marks the column name in the table for that particular attribute.