- Create a Spring boot project on Spring Initializr (add the dependencies: Spring web, MySQL Driver and Spring Data JPA
- Run MySQL server process in a docker container: Start docker desktop (windows) and type this in the command prompt tool (substitute the name and password fields with your chosen ones):
- docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=<db_name> -e MYSQL_USER= -e MYSQL_PASSWORD= -p 3306:3306 -d mysql:8
- docker exec -it mysql mysql -u myuser -p (to get inside the MySQL server running inside the container)
- Optionally, connect to this DB in MySQL Workbench
- Add the following application.yaml to the project (check repo for its path):
spring: datasource: url: jdbc:mysql://localhost:3306/<db_name> username: <username> password: <password> driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: ddl-auto: update # (for dev only) show-sql: true
- Use Postman to test the API. For example, for creating an entry in the table (it is named cloud_vendor_info), paste the following in the Body (raw) field of POST request (at http://localhost:8080/cloudvendors) and hit 'Send':
{ "vendorName": "ABC", "vendorId": "Vendor 1", "vendorAddress": "PQR", "vendorPhoneNumber": "123-456-7890" }
- Similarly, try other operations (GET/PUT/DELETE)
-
Notifications
You must be signed in to change notification settings - Fork 0
A simple Java REST API project demonstrating the Controller, Service and Repository layers for implementing CRUD operations in a MySQL DB, using Springboot and Spring Data JPA. (credits: https://www.youtube.com/watch?v=RfHBm5yRxuw)
adityaSS13/RESTful-API-demonstrating-CRUD-operations-using-Springboot-and-MySQL
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
A simple Java REST API project demonstrating the Controller, Service and Repository layers for implementing CRUD operations in a MySQL DB, using Springboot and Spring Data JPA. (credits: https://www.youtube.com/watch?v=RfHBm5yRxuw)
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published