Javatpoint Logo
Javatpoint Logo

Spring MVC CRUD Example

CRUD (Create, Read, Update and Delete) application is the most important application for creating any project. It provides an idea to develop a large project. In spring MVC, we can develop a simple CRUD application.

Here, we are using JdbcTemplate for database interaction.

Create a table

Here, we are using emp99 table present in the MySQL database. It has 4 fields: id, name, salary, and designation. Here, id is auto incremented which is generated by the sequence.

Spring MVC CRUD Example

Spring MVC CRUD Example

1. Add dependencies to pom.xml file.

pom.xml

2. Create the bean class

Here, the bean class contains the variables (along setter and getter methods) corresponding to the fields exist in the database.

Emp.java

3. Create the controller class

EmpController.java

4. Create the DAO class

Let's create a DAO class to access the required data from the database.

EmpDao.java

5. Provide the entry of controller in the web.xml file

web.xml

6. Define the bean in the xml file

spring-servlet.xml

7. Create the requested page

index.jsp

8. Create the other view components

empform.jsp

empeditform.jsp

Here "/SpringMVCCRUDSimple" is the project name, change this if you have different project name. For live application, you can provide full URL.

viewemp.jsp

Output:

Spring MVC CRUD Example

On clicking Add Employee, you will see the following form.

Spring MVC CRUD Example

Fill the form and click Save to add the entry into the database.

Spring MVC CRUD Example

Now, click Edit to make some changes in the provided data.

Spring MVC CRUD Example

Now, click Edit Save to add the entry with changes into the database.

Spring MVC CRUD Example

Now, click Delete to delete the entry from the database.

Spring MVC CRUD Example

Download SQL File

Download SQL File

Download MYSQL-connector.jar file

If you are not using maven, download MYSQL-connector.jar.





Please Share

facebook twitter google plus pinterest

B.Tech / MCA


Learn Latest Tutorials