Skip to content

Spring Boot REST API using layered architecture with DAO, Service, and Controller. Includes basic CRUD operations and database integration with JPA.

Notifications You must be signed in to change notification settings

patodemjan/Spring-Crud-with-Services

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring-Crud-with-Services

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.


Features

  • 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

Technologies Used

  • 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)

Getting Started

Prerequisites

  • Java 17+
  • Maven
  • IDE (Eclipse, IntelliJ, VS Code)
  • Git

Running the Application

  1. 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.

About

Spring Boot REST API using layered architecture with DAO, Service, and Controller. Includes basic CRUD operations and database integration with JPA.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages