Spring boot crud example with MySQL and Postman

Here we are discussing the Spring boot crud example with MySQL that will include all basic operations few queries for JPA and check responsesProject using Postman.

Project Explorer for Spring boot crud example with MySQL

Project Explorer: Spring Boot CRUD Project
Project Explorer: Spring Boot CRUD Project

Starting Spring boot Project with Spring Initializer

Open Spring Initializer

Spring Initializer create starting spring boot project
Fig: Spring Initializer creates starting spring boot project

Click on Generate it will download file.

Open Eclipse IDE -> File-> import->Existing Maven Project.

Then import the project from a specific directory.

Open Java Resources-> src/main/java

then create packages


Creating MySql Database

We have created a user and password and given all privileges to that account. created a database and created a table student.

To connect with the database all properties are at application.properties available in src/main/resources

Creating Files in Spring Boot Project

Entity Class

inside the com.univ.app.entity create a Student class (Student.java)

This class contains all filed that are available in the database and also its mapping.

Controller Class

Create StudentController inside com.univ.app.controller as below

We have created basic methods to add, update, delete, and fetch the record, also included methods to fetch records based on semester and course and the user can also update few fields separately like mail id and mobileNo.

The rest controller is used to access the data with different mapping styles like GetMapping, PostMapping, PutMapping etc.

Service class

StudentService.java inside com.univ.app.service

@Service annotation is used to make it a service class and dao is autowired to interact with StudentDAO.

DAO class

@Repository annotation is used to access data from a database.

StudentDAO extends JPARepositiiry.

Created Query for finding students by first name, course, and semester also created query for updating email and mobileNo.

Checking Rest API with Postman

open postman and call APIs created in the controller. We called a few APIs as below.

Add Student API call

Spring boot postman add API test
Spring boot Postman add API test

Get a Student with id

Update User Details

Similar way you can test all other APIs

Read More

Angular Spring Boot showing data in table

SpringBoot JPA @OneToMany Mapping : Fetch data from tables