This is a Spring Boot application that implements CRUD operations for Student and Course entities with MySQL database integration.
- Student entity with email validation
- Prevents duplicate students with same email
- Returns "The student already exists" message for duplicates
- Complete CRUD operations for Course entity
- Course fields: id, title, credits
- Full REST API implementation
- Java 17 or higher
- Maven 3.6+
- MySQL 8.0+
-
Database Setup
CREATE DATABASE student_course_db;
-
Configure Database Update
src/main/resources/application.propertieswith your MySQL credentials:spring.datasource.username=your_username spring.datasource.password=your_password
-
Run Application
mvn spring-boot:run
POST /api/students- Create new student (with email validation)GET /api/students- Get all studentsGET /api/students/{id}- Get student by IDPUT /api/students/{id}- Update studentDELETE /api/students/{id}- Delete student
POST /api/courses- Create new courseGET /api/courses- Get all coursesGET /api/courses/{id}- Get course by IDPUT /api/courses/{id}- Update courseDELETE /api/courses/{id}- Delete course
{
"name": "John Doe",
"email": "[email protected]",
"age": 20
}{
"title": "Introduction to Computer Science",
"credits": 3
}- Start the application
- Import the endpoints into Postman
- Test all CRUD operations
- Verify email validation for students
- Check error handling for invalid requests
src/main/java/com/assignment/crud/
├── CrudApplication.java # Main application class
├── entity/
│ ├── Student.java # Student entity
│ └── Course.java # Course entity
├── repository/
│ ├── StudentRepository.java # Student data access
│ └── CourseRepository.java # Course data access
├── service/
│ ├── StudentService.java # Student business logic
│ └── CourseService.java # Course business logic
└── controller/
├── StudentController.java # Student REST endpoints
└── CourseController.java # Course REST endpoints