This is an educational Spring Boot REST API for managing employees, departments, addresses, profiles, and simple login/logout state. The app uses Spring Web, Spring Data JPA, Bean Validation, and MySQL for local development.
- Java 11
- Spring Boot 2.7.x
- Spring Web
- Spring Data JPA
- MySQL Connector/J
- H2 for automated tests
- Maven Wrapper
.
|-- pom.xml
|-- mvnw / mvnw.cmd
|-- src/
| |-- main/
| | |-- java/com/hemant/db/
| | | |-- SpringbootMysqlApplication.java
| | | |-- exception/
| | | |-- model/
| | | |-- repository/
| | | |-- resource/
| | | `-- service/
| | `-- resources/application.yml
| `-- test/
| |-- java/com/hemant/db/
| `-- resources/application-test.yml
`-- .github/workflows/ci.yml
model contains the JPA entities that map to database tables. Examples:
Employee, Department, Address, and Profile.
repository contains Spring Data JPA repositories. These interfaces provide
database access methods such as findByEmail, findByCity, and findByName.
service contains business logic. Controllers call services instead of talking
directly to repositories, which keeps request handling and application rules
separate.
resource contains REST controllers. These preserve the original /rest/...
routes while delegating work to services.
exception contains shared API error handling. Missing records, duplicate
records, bad requests, and validation failures return consistent JSON error
responses.
The app reads database settings from environment variables with local defaults:
| Variable | Default |
|---|---|
MYSQL_URL |
jdbc:mysql://localhost:3306/employee_db |
MYSQL_USERNAME |
root |
MYSQL_PASSWORD |
empty |
JPA_DDL_AUTO |
update |
JPA_SHOW_SQL |
true |
Example PowerShell setup:
$env:MYSQL_URL="jdbc:mysql://localhost:3306/employee_db"
$env:MYSQL_USERNAME="root"
$env:MYSQL_PASSWORD="your-password"Start MySQL and create the database:
CREATE DATABASE employee_db;Then run the application:
.\mvnw.cmd spring-boot:runOn macOS/Linux:
./mvnw spring-boot:runThe API starts on the default Spring Boot port:
http://localhost:8080
The existing route style is preserved.
GET /rest/Employee/allPOST /rest/Employee/insertGET /rest/Employee/findbyname?name=...GET /rest/Employee/findbydesignation?designation=...POST /rest/Employee/updatedesignation?Id=...&designation=...POST /rest/Employee/updatemobile?Id=...&mobile=...POST /rest/Employee/updatepassword?Id=...&password=...DELETE /rest/Employee/delete?Id=...
GET /rest/Department/allPOST /rest/Department/insertGET /rest/Department/findbyname?name=...GET /rest/Department/findbyaddress?address=...POST /rest/Department/updatefloor?Id=...&floor=...POST /rest/Department/updateaddress?Id=...&address=...DELETE /rest/Department/delete?Id=...
GET /rest/Address/allPOST /rest/Address/insertGET /rest/Address/findbycity?city=...GET /rest/Address/findbystate?state=...POST /rest/Address/updateaddress?...DELETE /rest/Address/delete?Id=...
GET /rest/Profile/allPOST /rest/Profile/insertGET /rest/Profile/findbygender?gender=...GET /rest/Profile/findbyhobbies?hobbies=...POST /rest/Profile/updatehobbies?Id=...&hobbies=...DELETE /rest/Profile/delete?Id=...
GET /rest/Login/findbyemail?email=...POST /rest/Login/login?email=...&password=...POST /rest/Login/logout?email=...
Tests use H2 in MySQL compatibility mode, so they do not require a local MySQL server.
.\mvnw.cmd testOn macOS/Linux:
./mvnw testThe GitHub Actions workflow also runs the Maven test suite on Java 11 for pushes
to main and pull requests.
- Passwords are accepted for create/update/login operations but are hidden from JSON responses.
- This project intentionally keeps the original route naming style to avoid breaking existing clients.
- Authentication is educational only. It stores a login status and plain password values, so it should not be used as-is for production security.