A Spring Boot REST API for employee management with full CRUD operations, validation, and testing.
- Complete CRUD operations for employee management
- Advanced search by ID, email, department, salary range, and name
- Data validation with custom error messages
- RESTful API with standard HTTP methods
- H2 in-memory database for quick setup
- Comprehensive testing (40 tests total)
- Pre-loaded with 8 sample employees
- Java 17
- Spring Boot 3.5.0
- Spring Data JPA
- H2 Database
- Maven
- JUnit 5
-
Clone & Run
git clone https://github.com/harshit-sharma2005/Employee-Management-System.git cd Employee-Management-System .\mvnw spring-boot:run
-
Access Application
- API: http://localhost:8081/api/employees
- H2 Console: http://localhost:8081/h2-console
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/employees |
Get all employees |
| GET | /api/employees/{id} |
Get employee by ID |
| GET | /api/employees/email/{email} |
Get employee by email |
| GET | /api/employees/department/{dept} |
Get employees by department |
| POST | /api/employees |
Create new employee |
| PUT | /api/employees/{id} |
Update employee |
| DELETE | /api/employees/{id} |
Delete employee |
Get All Employees:
curl http://localhost:8081/api/employeesCreate Employee:
curl -X POST http://localhost:8081/api/employees \
-H "Content-Type: application/json" \
-d '{
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"department": "IT",
"salary": 75000.0
}'# Run all tests
.\mvnw test
# Test specific class
.\mvnw test -Dtest=EmployeeControllerTestPre-loaded with 8 employees across IT, HR, Finance, and Marketing departments.
Database: H2 In-Memory
- URL:
jdbc:h2:mem:testdb - Username:
sa - Password:
password
Server Port: 8081
Employee fields include validation for:
- Required fields (firstName, lastName, email, department, salary)
- Email format validation
- Custom error messages
Port conflict:
netstat -ano | findstr :8081
taskkill /PID <process-id> /FJava version: Requires Java 17+
MIT License