This project implements CRUD (Create, Read, Update, Delete) operations for managing employees, using RESTful APIs in Java with Spring Boot. The system allows users to create, view, update, and delete employee records in a database.
- Features
- Technologies
- Prerequisites
- Setup and Installation
- API Endpoints
- Project Structure
- Running the Application
- License
- Create Employee: Add a new employee record to the database.
- Retrieve Employee: Fetch employee details by ID or list all employees.
- Update Employee: Modify employee information.
- Delete Employee: Remove employee records.
- Java 11+
- Spring Boot
- Spring Data JPA
- RESTful API
- PostgreSQL/MySQL (any preferred relational database)
- Maven
- Java 11 or above
- Maven 3.6+
- PostgreSQL/MySQL database
- IDE like IntelliJ IDEA, Eclipse, or VS Code
-
Clone the repository:
git clone https://github.com/your-username/employee-management-system.git cd employee-management-system -
Configure the database:
Open
src/main/resources/application.propertiesand update the database settings with your own.spring.datasource.url=jdbc:postgresql://localhost:5432/employee_db spring.datasource.username=your_username spring.datasource.password=your_password spring.jpa.hibernate.ddl-auto=update
-
Build the project:
Run the following Maven command to build the project:
mvn clean install
-
Run the application:
You can now run the application using:
mvn spring-boot:run
- URL:
/api/employees - Method:
POST - Request Body:
{ "firstName": "John", "lastName": "Doe", "email": "john.doe@example.com", "position": "Software Engineer" } - Response: HTTP 201 Created
- URL:
/api/employees - Method:
GET - Response: List of employee records
- URL:
/api/employees/{id} - Method:
GET - Response: Employee record
- URL:
/api/employees/{id} - Method:
PUT - Request Body:
{ "firstName": "Jane", "lastName": "Doe", "email": "jane.doe@example.com", "position": "Manager" } - Response: HTTP 200 OK
- URL:
/api/employees/{id} - Method:
DELETE - Response: HTTP 204 No Content
src
│
├── main
│ ├── java
│ │ └── com.example.employee
│ │ ├── controller # REST controllers
│ │ ├── model # Employee entity
│ │ ├── repository # Repository interface for database operations
│ │ ├── service # Service layer for business logic
│ │ └── EmployeeManagementApplication.java # Main Spring Boot application class
│ └── resources
│ └── application.properties # Application configuration
│
└── test
└── java
└── com.example.employee # Unit and integration tests
After following the setup steps, you can run the application using:
mvn spring-boot:runOnce the application is running, you can access the API endpoints via a tool like Postman or Curl.