Spring Boot CRUD Tutorial for Freshers: Build an Employee API with MySQL Step by Step
Quick answer: A Spring Boot CRUD tutorial teaches you the four actions every application needs: Create, Read, Update and Delete. In this guide you will build an Employee REST API with Spring Boot, Spring Data JPA and MySQL, add validation and a global exception handler, and test every endpoint in Postman. You will use the standard layers (Controller, Service, Repository, Entity) that interviewers love to ask about. Follow the steps in order, type the code yourself and push the finished project to GitHub. This tutorial from VibrantMinds Technologies in Pune is written for freshers who want a real, explainable project.
It is for students and freshers who search for Spring Boot CRUD example, Spring Boot REST API with MySQL, how to connect Spring Boot to MySQL, Spring Data JPA CRUD, Spring Boot project for freshers or employee management project in Spring Boot.
Versions change over time. This tutorial follows common Spring Boot 3 practice (Java 17 or newer, jakarta packages). Check the official Spring documentation for the latest setup. No salary figures, statistics or job guarantees are given.
What You Will Build
An Employee API with these endpoints:
Action
HTTP method
Endpoint
What it does
Create
POST
/api/employees
Add a new employee
Read all
GET
/api/employees
List all employees
Read one
GET
/api/employees/{id}
Get one employee by id
Update
PUT
/api/employees/{id}
Change an employee's details
Delete
DELETE
/api/employees/{id}
Remove an employee
Request flow you will implement:
Postman → Controller → Service → Repository → MySQL → back to Postman
What You Need Before You Start
Java 17 or newer (JDK installed)
An IDE: IntelliJ IDEA, Eclipse or VS Code
MySQL installed and running, plus a client (MySQL Workbench or the command line)
Maven (comes with most IDEs)
Postman (to test the API)
Git (to push your project to GitHub)
Step 1: Create the MySQL Database
Open your MySQL client and run:
sql
CREATE DATABASE employee_db;
CREATE DATABASE employee_db;
CREATE DATABASE employee_db;
You do not need to create the table. Spring Data JPA can create it for us from the entity class (in development).
Step 2: Create the Spring Boot Project
Go to the official Spring Initializr website (start.spring.io) or use your IDE's Spring Initializr option. Choose:
Project: Maven
Language: Java
Spring Boot: a stable 3.x version
Group:com.example
Artifact:employee-api
Packaging: Jar
Java: 17 or newer
Dependencies:Spring Web, Spring Data JPA, MySQL Driver, Validation
Generate, download, unzip and open the project in your IDE.
Why this is powerful: By extending JpaRepository, you get save, findAll, findById, deleteById and more without writing any SQL or implementation.existsByEmail is a derived query: Spring creates the query from the method name.
Step 13: Understand What Happened (The Request Flow)
When you send POST /api/employees:
Controller receives the request and converts the JSON into an Employee object (@RequestBody).
Validation runs because of @Valid. If a rule fails, the exception handler returns 400.
Service checks business rules, such as duplicate email.
Repository calls save(), and Hibernate runs an INSERT in MySQL.
The saved object returns up through the layers.
The controller sends 201 Created with JSON.
Practise saying this flow aloud. It is one of the most common fresher interview questions.
Common Errors and How to Fix Them
Error you see
Likely cause
Fix
Communications link failure
MySQL is not running or the URL or port is wrong
Start MySQL and check spring.datasource.url
Access denied for user
Wrong username or password
Correct them in application.properties
Unknown database 'employee_db'
The database was not created
Run CREATE DATABASE employee_db;
Table 'employees' doesn't exist
ddl-auto setting is missing
Set spring.jpa.hibernate.ddl-auto=update while learning
Port 8080 was already in use
Another app uses the port
Stop it, or set server.port=8081
HTTP 415 Unsupported Media Type
Missing JSON header in Postman
Set body to raw JSON and Content-Type: application/json
HTTP 400 on a valid body
A validation rule failed
Read the error message in the response
Fields are null after save
Missing getters and setters or wrong JSON names
Add getters and setters and match field names
NoSuchBeanDefinitionException
Class is outside the main package or missing an annotation
Keep packages under com.example.employeeapi and add @Service or @Repository
jakarta import errors
Mixing old javax imports with Spring Boot 3
Use jakarta.* imports in Spring Boot 3
Improve the Project: Next Steps That Impress Interviewers
Upgrade
Why it helps
DTOs (separate request and response classes)
Do not expose entities directly. Cleaner and safer.
Pagination and sorting
Use Pageable with findAll(Pageable) for large lists
Search endpoint
Add findByDepartment or findByNameContaining in the repository
Unit tests
JUnit and Mockito tests for the service layer
Integration tests
@SpringBootTest with a test database
Logging
Use SLF4J logging in the service layer
Swagger / OpenAPI
Auto-generated API documentation
Security
Add Spring Security with login and roles
Docker
Run the API and MySQL with Docker Compose
A simple front end
HTML, CSS and JavaScript page that calls your API
Pick two or three and add them one by one. Each upgrade is a new talking point.
Put It on GitHub and Your Resume
Create a .gitignore (Spring Initializr creates one) so target/ is not uploaded.
Remove real passwords from application.properties before pushing.
Write a README with: project goal, tech stack, setup steps, endpoint list, sample requests and screenshots of Postman tests.
Make small, clear commits.
Add the link to your resume.
Resume line example (use only what is true):
Built an Employee Management REST API using Spring Boot, Spring Data JPA and MySQL with validation, global exception handling and Postman-tested CRUD endpoints. (GitHub link)
Interview Questions on This Project
Q1. Explain the layers of your project. Controller handles HTTP requests, service holds business rules, repository talks to the database, and the entity maps to a table.
Q2. What does @RestController do? It combines @Controller and @ResponseBody, so methods return data (usually JSON) instead of views.
Q3. What is JpaRepository? A Spring Data interface that provides ready-made CRUD methods like save, findAll, findById and deleteById without writing implementations.
Q4. What is the difference between @Controller and @RestController? @Controller is typically used for returning views, while @RestController returns data directly in the response body.
Q5. What do @Valid and @NotBlank do? @Valid triggers validation on the request object, and @NotBlank makes sure a text field is not null or empty.
Q6. Why use a global exception handler? To return clear, consistent error responses and avoid repeating try and catch blocks in every controller method.
Q7. What is the difference between PUT and PATCH? PUT usually replaces the whole resource, while PATCH updates only some fields.
Q8. What does ddl-auto=update do, and is it safe for production? It updates the database schema from the entities. It is convenient while learning, but teams usually use migration tools and stricter settings in production.
Q9. Why should you not expose entities directly in APIs? It can leak internal structure and cause tight coupling. DTOs give you control over what is sent and received.
Q10. How would you add pagination? Use Pageable in the controller, call repository.findAll(pageable) and return a Page of results.
How VibrantMinds Technologies Helps You Build Real Projects
VibrantMinds Technologies Pvt. Ltd. is a Pune-based company that provides Java Full Stack training and placement support for freshers. If you searched for VibrantMinds or VibrantMinds Technologies, here is what that means:
Java Full Stack training (about 4 to 6 months): Core Java, Advanced Java, Java 8, SQL, Hibernate, Spring, Spring Boot, REST APIs, HTML, CSS and JavaScript, with data structures practice, projects, aptitude and communication training, group discussion and interview preparation. Please check the candidate portal for the latest syllabus and tools.
Project practice and feedback, so you build applications like this one and can explain every layer.
Mock interviews and aptitude practice to find your gaps before a real interview does.
Placement support: screening and assessment, drive coordination and interview support. Current openings are listed at https://candidates.vibrantminds.in/
VibrantMinds works as a talent ecosystem connecting candidates, colleges and hiring companies, with 1900+ partner colleges and 600+ hiring companies. Its placement support process runs in six steps: Requirement Mapping, Candidate Sourcing, Screening and Assessment, Drive Coordination, Interview Support and Onboarding Follow-up.
Past students have gone on to roles at companies such as Aress Software and Education Technologies, Saama Technologies and Three M Software. Results vary by candidate, skill level, effort and market conditions. VibrantMinds offers placement support, not a guaranteed job, and no legitimate recruiter should ask you to pay to be interviewed. Fees, syllabus and batch dates are on https://candidates.vibrantminds.in/ and should be confirmed directly before enrolling.
Join Free VibrantMinds WhatsApp Groups for Fresher IT Job Updates
Looking for free WhatsApp groups, free IT job WhatsApp groups, a Java WhatsApp group for freshers or a job updates WhatsApp group in India? The VibrantMinds groups share fresher IT openings, campus and off-campus drives, walk-in interview alerts and interview preparation updates, free of charge, and they are open to freshers from every college. Join whichever group has space:
Never pay to apply. Legitimate recruiters do not charge candidates for tests, interviews or offer letters. Do not share OTPs, bank details or ID numbers with anyone you have not verified.
Frequently Asked Questions
1. How do I build a CRUD REST API in Spring Boot with MySQL? Create a Spring Boot project with Spring Web, Spring Data JPA, MySQL Driver and Validation. Configure the database in application.properties, create an entity, a JpaRepository interface, a service class and a @RestController with POST, GET, PUT and DELETE methods. Add validation and a global exception handler, then test each endpoint in Postman.
2. How do I connect Spring Boot to MySQL? Add the MySQL driver dependency, create a database, and set spring.datasource.url, spring.datasource.username and spring.datasource.password in application.properties. Make sure MySQL is running. Use spring.jpa.hibernate.ddl-auto=update while learning so tables are created from your entities.
3. What are the layers of a Spring Boot application? Controller (handles HTTP requests and responses), service (business logic), repository (database access with Spring Data JPA) and entity (a Java class mapped to a table). Keeping layers separate makes code easier to test and change.
4. Why is my Spring Boot MySQL connection failing? Common causes are MySQL not running, a wrong URL or port, a wrong username or password, or a missing database. Check the error message, confirm you can log in with the same credentials in MySQL Workbench or the command line and then update application.properties.
5. Is there a free WhatsApp group for IT freshers in Pune? Yes. VibrantMinds runs free fresher IT job WhatsApp groups that share openings, drives and walk-in alerts. Join through the links in this article, verify every post and never pay to apply.
Conclusion: One Working CRUD Project Is a Strong Start
You have now built a complete Spring Boot CRUD application with MySQL: an entity, repository, service, controller, validation, a global exception handler and a full set of Postman tests. Practise explaining the request flow aloud, add two or three upgrades such as DTOs, pagination and unit tests, push the project to GitHub with a clear README and put it on your resume honestly. A project you can build from scratch and explain clearly improves your chances in interviews, though no one can promise a particular result.
If you are in Pune and want Java Full Stack training with project practice, interview preparation and placement support, VibrantMinds Technologies is here to help.
Contact VibrantMinds Technologies Pvt. Ltd.
Address: Viva Academy Building, Warje, Pune, Maharashtra 411052