Spring Boot REST API for managing catalog items and item details with JPA, MySQL persistence, query-based filtering, and layered controller-service-repository design.
This project demonstrates a compact Spring Boot API for managing product-like catalog items. It models each item with linked detail data such as brand, price, and category, and extends the original CRUD-style workflow with named-query and native-query based filtering endpoints for stronger catalog-search learning value.
- Spring Boot REST API setup
- Spring Data JPA repository pattern
- MySQL-backed persistence
- One-to-one relationship between
ItemandItemDetails GETendpoint for retrieving an item by IDGETendpoint for listing all itemsPOSTendpoint for saving an item with detailsPUTendpoint for updating an itemDELETEendpoint for deleting an item by IDDELETEendpoint for deleting item details by ID- Native query based item search by description prefix
- Derived query for item details above a given price
- Named query for item details by category ordered by price
- Java 8
- Spring Boot 2.7
- Spring Web
- Spring Data JPA
- MySQL
- Maven
- JUnit 5
cnkart/
├── CHANGELOG.md
├── README.md
├── pom.xml
├── mvnw
├── mvnw.cmd
└── src/
├── main/
│ ├── java/com/cn/ecommerce/
│ │ ├── controller/
│ │ ├── dao/
│ │ ├── entity/
│ │ ├── service/
│ │ └── EcommerceApplication.java
│ └── resources/
│ └── application.yml
└── test/
└── java/com/cn/ecommerce/
└── EcommerceApplicationTests.java
- Open a terminal in the project root.
- Update the MySQL connection values in
src/main/resources/application.ymlif needed. - Run
mvn test. - Run
mvn spring-boot:run. - Use the API under
http://localhost:8080.
Available endpoints:
GET /api/item/{id}GET /api/itemPOST /api/item/savePUT /api/item/updateDELETE /api/item/{id}GET /api/item/desc/{desc}DELETE /api/details/item/{id}GET /api/details/item/price/{price}GET /api/details/item/category/{category}
Example request body:
{
"name": "Wireless Mouse",
"description": "Compact Bluetooth mouse",
"itemDetails": {
"brand": "LogiTech",
"price": 1299.0,
"category": "Accessories"
}
}- Demonstrates how to model one-to-one entity relationships with JPA
- Shows a clean separation between controllers, services, and repository access
- Adds native-query, named-query, and derived-query examples in one compact project
- Keeps the API surface compact while still covering create, read, update, delete, and filter flows
- Works well as a starter project for relational CRUD APIs with Spring Boot
- Suggested repository description:
Spring Boot REST API for managing catalog items and item details with JPA, MySQL persistence, plus native-query and named-query catalog filtering. - Suggested topics:
java,spring-boot,spring-data-jpa,mysql,rest-api,crud-api,ecommerce,catalog-management,native-query,named-query,maven,learning-project,portfolio-project