This is a simple Spring Boot RESTful API project demonstrating a CRUD (Create, Read, Update, Delete) application with a layered architecture.
The project manages Employee
entities and includes Controller, Service, DAO layers using Spring, JPA, and Hibernate.
- REST API for Employee entity
- CRUD operations:
- Get all employees
- Get employee by ID
- Create new employee
- Update existing employee
- Delete employee by ID
- Uses Service layer for business logic
- DAO layer implemented with JPA and EntityManager
- Transaction management with
@Transactional
- Proper layering: Controller -> Service -> DAO -> Entity
- Java 17 (or higher)
- Spring Boot
- Spring Data JPA (with EntityManager)
- Hibernate
- Maven
- H2 (or any other database configured by you)
- Jakarta Persistence API (JPA)
- Java 17+
- Maven
- IDE (Eclipse, IntelliJ, VS Code)
- Git
- Clone the repository:
git clone https://github.com/patodemjan/Spring-Crud-with-Services.git Navigate to the project folder:
cd Spring-Crud-with-Services
Build the project with Maven:
mvn clean install
Run the Spring Boot application:
mvn spring-boot:run
The API will start on http://localhost:8080/api/employees. API Endpoints HTTP Method Endpoint Description GET /api/employees Get all employees GET /api/employees/{id} Get employee by ID POST /api/employees Create new employee PUT /api/employees Update existing employee DELETE /api/employees/{id} Delete employee by ID Example Request with curl
Create a new employee:
curl -X POST -H "Content-Type: application/json" -d '{"firstName":"John", "lastName":"Doe", "email":"[email protected]"}' http://localhost:8080/api/employees
Get all employees:
curl http://localhost:8080/api/employees
Notes
Make sure to configure your database connection in application.properties.
Consider adding validation and exception handling for production use.
This is a learning/demo project and can be extended with DTOs, unit/integration tests, and API documentation.
License
This project is licensed under the MIT License - see the LICENSE file for details.