This project is a Spring Boot application that provides a RESTful API for performing CRUD (Create, Read, Update, Delete) operations on a Student
entity. The application uses Spring Data JPA to interact with a MySQL database.
Before running the application, make sure you have the following prerequisites installed:
- Java Development Kit (JDK) 17 or higher
- Maven
- MySQL Server (or any other compatible database)
- Clone the repository:
git clone https://github.com/your-username/spring-boot-rest-api-crud.git
- Navigate to the project directory:
cd spring-boot-rest-api-crud
- Configure the database connection:
Open the application.properties
file and update the following properties with your MySQL database credentials:
spring.datasource.url=jdbc:mysql://localhost:3306/your_database_name
spring.datasource.username=your_username
spring.datasource.password=your_password
- Build the project:
mvn clean package
- Run the application:
java -jar target/your-app.jar
Replace your-app.jar
with the actual name of your built JAR file.
The application provides the following API endpoints:
GET /students
: Retrieve a list of all studentsGET /students/{id}
: Retrieve a student by IDPOST /students
: Create a new studentPUT /students/{id}
: Update an existing studentDELETE /students/{id}
: Delete a student
Response:
[
{
"id": 1,
"name": "John Doe",
"age": 25
},
{
"id": 2,
"name": "Jane Smith",
"age": 22
}
]
Request Body:
{
"name": "New Student",
"age": 20
}
Response:
{
"id": 3,
"name": "New Student",
"age": 20
}
This project can be containerized using Docker. Follow these steps to build and run the application as a Docker container:
- Build the Docker image:
docker build -t spring-boot-rest-api .
- Run the Docker container:
docker run -p 8080:8080 spring-boot-rest-api
This command will start the container and map port 8080 of the container to port 8080 on your host machine.
- Access the application at
http://localhost:8080
.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.