DEV Community

Cover image for πŸš€ Spring Boot Journey – Day 3: Mastering CRUD Operations, Lombok & JPA Query Methods
Ashish prajapati
Ashish prajapati

Posted on

πŸš€ Spring Boot Journey – Day 3: Mastering CRUD Operations, Lombok & JPA Query Methods

Welcome to Day 3 of my Spring Boot learning journey! πŸ’š

Today's session was packed with practical concepts that are used in almost every real-world Spring Boot application. I moved beyond creating simple APIs and started building a complete CRUD application while learning how Spring Boot simplifies backend development.


πŸ“Œ What I Learned Today

Today I implemented the complete CRUD (Create, Read, Update, Delete) functionality for my Student Management application.

The REST APIs now support:

  • βž• Create a Student
  • πŸ“– Read all Students
  • πŸ” Read a single Student
  • ✏️ Update Student details
  • ❌ Delete a Student

I also learned how different HTTP methods map to REST APIs:

  • POST β†’ Create Data
  • GET β†’ Fetch Data
  • PUT β†’ Update Data
  • DELETE β†’ Remove Data

Understanding these methods helped me see how backend APIs communicate with frontend applications.


πŸ“š Adding Multiple Records

Instead of inserting one record at a time, I learned how to save multiple student records using a single API request.

Spring Data JPA provides the saveAll() method, making bulk insertion extremely simple and efficient.

This feature is especially useful when importing large datasets.


⚑ Making Code Cleaner with Lombok

One of my favorite topics today was Lombok.

Previously, every entity required writing:

  • Constructors
  • Getters
  • Setters
  • toString()
  • equals()
  • hashCode()

Now, with just a few annotations like:

  • @Data
  • @NoArgsConstructor
  • @AllArgsConstructor

Lombok generates all that code automatically.

This makes the project cleaner, shorter, and much easier to maintain.


πŸ—„οΈ Repository Layer with Spring Data JPA

Today I explored the power of Spring Data JPA.

Instead of writing SQL queries manually, Spring Boot generates queries automatically based on method names.

Some custom repository methods I added include:

  • Find students by department
  • Find students whose date of birth is after a given date
  • Find students whose date of birth is before a given date

It was amazing to see that simply naming methods correctly allows Spring Boot to generate the required SQL behind the scenes.


πŸ” JPA Query Methods

Today I learned about Query Method Naming in Spring Data JPA.

Examples include:

  • findByDepartment()
  • findByDobAfter()
  • findByDobBefore()

Spring Boot automatically understands these method names and creates the appropriate database queries without requiring any SQL.

This is one of the features that makes Spring Data JPA so powerful and developer-friendly.


⚠️ Exception Handling

Applications should never fail silently.

To improve my project, I implemented exception handling for situations where a student record doesn't exist.

Now, instead of unexpected behavior, the application returns a meaningful error message when someone tries to access or delete a student that isn't available.

This improves both reliability and user experience.


πŸ—οΈ Project Architecture

My project now follows the standard layered architecture:

Client Request

⬇️

Controller

⬇️

Service

⬇️

Repository

⬇️

MySQL Database

⬇️

Response

Keeping responsibilities separated makes the application easier to understand, test, and maintain.


πŸ“– Key Concepts Covered Today

βœ… CRUD Operations

βœ… HTTP Methods (GET, POST, PUT, DELETE)

βœ… Bulk Insert using saveAll()

βœ… Lombok Annotations

βœ… Spring Data JPA Repository

βœ… JPA Query Methods

βœ… Filtering Data using Repository Methods

βœ… Exception Handling

βœ… Layered Architecture


πŸ’­ My Takeaway

Today's session made me realize how much Spring Boot reduces repetitive work.

With Lombok, I no longer need to write boilerplate code.

With Spring Data JPA, I can fetch filtered data without writing SQL.

And with proper exception handling, my APIs become much more reliable.

Every day I'm getting closer to building production-ready backend applications, and it's exciting to see how everything connects together.

Looking forward to learning more advanced Spring Boot concepts in the coming days! πŸš€


#SpringBootJourney Day 3

Today's progress:

βœ” CRUD Operations

βœ” Lombok

βœ” JPA Repository

βœ” Query Methods

βœ” Exception Handling

One day. One project. One step closer to becoming a Java Backend Developer. πŸ’š

Top comments (0)