This is a simple Spring Boot application that performs CRUD operations on products. Each product has a unique ID, name, and price. The application uses MySQL as the database and leverages Spring Data JPA for ORM and Spring Web for creating RESTful web services.
- Add new products
- Retrieve all products
- Retrieve a product by its ID
- Update an existing product
- Delete a product
- Spring Boot
- Spring Data JPA
- MySQL
- Spring Boot DevTools
- Maven
- Postman (for API testing)
- Java 8 or higher
- Maven 3.6 or higher
- MySQL
- Postman (for API testing)
Setup Instructions spring.datasource.url=jdbc:mysql://localhost:3306/productdb spring.datasource.username=your-username spring.datasource.password=your-password spring.jpa.hibernate.ddl-auto=update
Update the application.properties file located in src/main/resources with your MySQL database configuration:
spring.datasource.url=jdbc:mysql://localhost:3306/productdb
spring.datasource.username=your-username
spring.datasource.password=your-password
spring.jpa.hibernate.ddl-auto=updateDownload and install Postman from here.
Create a new collection in Postman and add the above API endpoints to test them.
To add a product, set the method to POST, the URL and the body to raw JSON.
http://localhost:8080/productsTo retrieve all products, set the method to GET and the URL
http://localhost:8080/productsTo retrieve a product by ID, set the method to GET and the URL to
http://localhost:8080/products/{id}To update a product, set the method to PUT, the URL and the body to raw JSON.
http://localhost:8080/productsTo delete a product, set the method to DELETE and the URL to
http://localhost:8080/products/{id}src
├── main
│ ├── java
│ │ └── com
│ │ └── example
│ │ └── productmanagement
│ │ ├── controller
│ │ │ └── ProductController.java
│ │ ├── model
│ │ │ └── Product.java
│ │ ├── repository
│ │ │ └── ProductRepository.java
│ │ └── ProductManagementApplication.java
│ └── resources
│ ├── application.properties
│ └── schema.sql
└── test
└── java
└── com
└── example
└── productmanagement
└── ProductManagementApplicationTests.java
GET /products| Parameter | Type | Description |
|---|---|---|
| `` | product |
It returns all the products in JSON |
GET /products/${id}| Parameter | Type | Description |
|---|---|---|
id |
int |
Required. Id of item to fetch |
POST /products| Parameter | Type | Description |
|---|---|---|
prodid |
int |
Required. Id of item to Create |
prodname |
int |
Required. Product Name of item to Create |
price |
int |
Required. Product Price of item to Create |
PUT /products| Parameter | Type | Description |
|---|---|---|
prodid |
int |
Required. Id of item to Update |
prodname |
int |
Required. Product Name of item to Update |
price |
int |
Required. Product Price of item to Update |
GET /products/{id}| Parameter | Type | Description |
|---|---|---|
id |
int |
Required. Id of item to Delete |