-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.md
101 lines (69 loc) · 4.11 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Spring Boot CRUD Operations with MySQL
This project demonstrates fundamental concepts of Java, Spring Boot, and MySQL by creating a simple application that interacts with a relational database.
**Key Features:**
* **Spring Boot:** Leverages the Spring Boot framework for rapid application development, including dependency injection, auto-configuration, and embedded servers.
* **MySQL:** Utilizes MySQL as the underlying database for data storage and retrieval.
* **JPA and Hibernate:** Employs Java Persistence API (JPA) and Hibernate as the Object-Relational Mapping (ORM) layer to interact with the database using Java objects.
* **CRUD Operations:** Implements core CRUD (Create, Read, Update, Delete) operations on a chosen entity (e.g., a User, Product) through a RESTful API.
* **RESTful API:** Exposes endpoints (e.g., GET, POST, PUT, DELETE) for interacting with the data using HTTP requests.
**Technical Steps:**
1. **Project Setup:**
* Create a Spring Boot project using Spring Initializr.
* Use Java version 17 or higher and Maven.
* Add dependencies for:
* Spring Web
* Spring Data JPA
* MySQL Driver
* Lombok
2. **Project Setup (After Cloning):**
* Run `mvn clean install` in the terminal to download all dependencies.
3. **Database Setup:**
* Create a database named `newdb` using the following SQL command:
```sql
create database newdb abcd;
```
* Important: Update the `username` and `password` in the `application.properties` file with your MySQL credentials.
4. **Run the Application:**
* Start the Spring Boot application using your preferred IDE or by running `mvn spring-boot:run` in the terminal.
5. **Explore and Experiment:**
* Use a tool like Postman to interact with the exposed RESTful endpoints.
* Test the CRUD operations using Postman.
* Modify the entity, service, and controller classes to explore different functionalities.
**Getting Started with Postman:**
1. Install Postman: https://www.getpostman.com/
2. Create a new collection for your project.
3. **Create Operation:**
* Set the request method to `POST`.
* Set the URL to `http://localhost:8080/addStd` (assuming the application runs on port 8080).
* In the Body tab, select `raw` and set the content type to `application/json`.
* Provide a JSON object representing the student data you want to create
```json
{"name": "John Doe","mark": 30}
```
* Send the request.
5. **Read Operation:**
* Set the request method to `GET`.
* Set the URL to `http://localhost:8080/getAllData` to retrieve all students.
* You can also use `http://localhost:8080/getStdById/{id}` to retrieve a specific student by ID, replacing `{id}` with the actual student ID.
* Send the request.
6. **Update Operation:**
* Set the request method to `PUT`.
* Set the URL to `http://localhost:8080/updStd`.
* In the Body tab, provide a JSON object representing the updated student data.
* Send the request.
7. **Delete Operation:** (**Not implemented in this example project**):
* You can implement a DELETE endpoint to remove students from the database. Refer to Spring Data JPA documentation for guidance.
This project provides a solid foundation for understanding core Spring Boot concepts and building more complex applications with database interactions.
**Result**
Student database:

Spring Starting:

Post student data in database using postman:

Get Student data by ID in postman:

**Note:**
* This README file provides a basic overview. For detailed instructions and implementation specifics, refer to the project's source code and comments.
* This project is intended for educational and learning purposes.
**I hope this enhanced README file is more informative and appealing!**