An open API service indexing awesome lists of open source software.

https://github.com/samchenyu/springmysqlstarter

Starter code for connecting MySQL database to a Spring Project
https://github.com/samchenyu/springmysqlstarter

mysql rest-api springboot

Last synced: about 1 month ago
JSON representation

Starter code for connecting MySQL database to a Spring Project

Awesome Lists containing this project

README

          

# SpringMySQLStarter

## Features
REST Controller: Includes a REST controller that provides endpoints for managing Student entities. You can perform CRUD operations (Create, Read, Update, Delete) on the Student records through these endpoints.

JPA Repository: Contains a JPA repository for interacting with the MySQL database. The repository provides methods to save, find, update, and delete Student records without the need to write complex SQL queries.

Student Entity: Defines a Student object that maps to a STUDENT table in the MySQL database. The entity includes fields for id, mark, and name, and uses annotations to define how these fields map to the table columns.

## Setup
Database Configuration: Update the application.properties file with your MySQL database connection details.

Run the Application: Start the Docker Container for MySQL, then Spring Boot application using your preferred method (e.g., mvn spring-boot:run or running from your IDE).

Access Endpoints: Use the REST endpoints provided by the controller to interact with the Student records. The base URL for the API is /students.

## Example Endpoints
Get All Students: GET /students
Get Student by ID: GET /students/{id}
Create Student: POST /students
Update Student: PUT /students/{id}

## Dependencies:
- Spring Web
- Spring Data JPA
- MySQL Driver
- Lombok

# Docker
Start container: ```docker-compose up -d ```
Docker status: ``` docker ps ```
Access MySQL: ``` docker exec -it mysql_container mysql -u user -p ```
MySQL: ``` SHOW DATABASES; ```
Exit MySQL ``` exit ```
Stop the container: ``` docker-compose down ```
Remove the container: ``` docker rm mysql_container ```
Remove the db_data: ``` docker rm db_data ```