Skip to content

About

This is a Simple CRUD operation in mySQL and Spring boot framework. This Spring boot backend take http api request form postman. And save the data to MySQL database.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

🎓 Spring Boot CRUD Operation — Student Management API

A clean, production-style CRUD REST API built with Spring Boot 4, Spring Data JPA, and MySQL, demonstrating layered architecture (Controller → Service → Repository) with support for both hard delete and soft delete.

This project is designed as a solid reference implementation of RESTful CRUD principles in Java — proper HTTP status codes, clean separation of concerns, and predictable API contracts.


📌 Table of Contents


✨ Features

  • ✅ Full CRUD operations for Student resources
  • ✅ Soft delete support (records are flagged, not physically removed)
  • ✅ Hard delete support (permanent removal)
  • ✅ Layered architecture — Controller / Service / Repository
  • ✅ Spring Data JPA with derived query methods
  • ✅ MySQL persistence with auto schema sync (ddl-auto=update)
  • ✅ Meaningful HTTP status codes (201, 302, 404, 200)

🛠 Tech Stack

Layer Technology
Language Java 21
Framework Spring Boot 4.1.0
Data Access Spring Data JPA / Hibernate
Database MySQL
Build Tool Maven
API Style REST (JSON)

🏗 Project Architecture

com.example.SpringBootCRUDOperation
│
├── Controller/
│   └── StudentController.java     # REST endpoints — handles HTTP requests/responses
│
├── Service/
│   └── StudentService.java        # Business logic layer
│
├── Repository/
│   └── StudentRepository.java     # Spring Data JPA repository interface
│
├── Entity/
│   └── Student.java               # JPA entity / database model
│
└── SpringBootCrudOperationApplication.java   # Application entry point

The application follows a classic three-tier layered architecture:

  1. Controller Layer — Exposes REST endpoints and handles request/response mapping.
  2. Service Layer — Encapsulates business rules (e.g., defaulting deleted = false, merging update fields).
  3. Repository Layer — Handles persistence via Spring Data JPA, including custom derived queries filtered by deleted status.

📄 For a deeper dive into design decisions, data flow diagrams, and implementation rationale, see the Architecture & Implementation Document section below.


🚀 Getting Started

Prerequisites

  • Java 21+
  • Maven 3.9+
  • MySQL 8+ running locally

1. Clone the repository

git clone https://github.com/<your-username>/SpringBootCRUDOperation.git
cd SpringBootCRUDOperation

2. Create the database

CREATE DATABASE student_crud_db;

3. Configure application.properties

See the Configuration section below.

4. Build and run

mvn clean install
mvn spring-boot:run

The application will start on http://localhost:8080 by default.


⚙️ Configuration

Update src/main/resources/application.properties with your local MySQL credentials:

spring.application.name=SpringBootCRUDOperation

spring.datasource.url=jdbc:mysql://localhost:3306/student_crud_db
spring.datasource.username=root
spring.datasource.password=your_password

spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

⚠️ Note: For production, avoid ddl-auto=update and never commit real credentials. Use environment variables or a secrets manager instead.


📡 API Reference

Base URL: /api/students

Method Endpoint Description Success Status
POST /create Create a new student 201 Created
GET /get?id={id} Get a single student by ID 302 Found
GET /getAll Get all active students 302 Found
PUT /update?id={id} Update an existing student 302 Found
DELETE /delete?id={id} Permanently delete a student 200 OK
PATCH /delete-soft?id={id} Soft-delete (flag) a student 200 OK

Example — Create Student

Request

POST /api/students/create
Content-Type: application/json

{
  "name": "John Doe",
  "email": "[email protected]",
  "age": 21,
  "rollNo": 101,
  "subject": "Computer Science"
}

Response 201 Created

{
  "id": 1,
  "name": "John Doe",
  "email": "[email protected]",
  "age": 21,
  "rollNo": 101,
  "subject": "Computer Science",
  "deleted": false
}

Example — Get All Students

Request

GET /api/students/getAll

Response 302 Found

[
  {
    "id": 1,
    "name": "John Doe",
    "email": "[email protected]",
    "age": 21,
    "rollNo": 101,
    "subject": "Computer Science",
    "deleted": false
  }
]

Example — Soft Delete Student

Request

PATCH /api/students/delete-soft?id=1

Response 200 OK

Record Deleted successfully

📄 Architecture & Implementation Documents

Detailed PDFs covering system design, data flow, request lifecycle, and implementation decisions:

📎 Simple CRUD Operations (PDF)

📎 Soft Delete Implementation (PDF)


🔭 Future Improvements

  • Add DTOs to decouple API contracts from JPA entities
  • Add global exception handling (@ControllerAdvice)
  • Add request validation (@Valid, Bean Validation)
  • Add pagination and sorting to getAll endpoint
  • Add Swagger/OpenAPI documentation
  • Add unit and integration tests
  • Externalize sensitive configuration via environment variables

📜 License

This project is open-source and available under the MIT License.


Built with ☕ and Spring Boot

About

This is a Simple CRUD operation in mySQL and Spring boot framework. This Spring boot backend take http api request form postman. And save the data to MySQL database.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages