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
- Host: GitHub
- URL: https://github.com/samchenyu/springmysqlstarter
- Owner: SamChenYu
- Created: 2024-08-06T04:33:15.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-22T15:06:13.000Z (over 1 year ago)
- Last Synced: 2025-09-08T05:46:55.484Z (9 months ago)
- Topics: mysql, rest-api, springboot
- Language: Java
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 ```