Welcome to Spring-o-Learn, a Spring Boot-based Library Management System. This project allows users to browse a list of books, add reviews, and delete all reviews associated with a book.
- View Books: Displays a list of books with their details (title, description, and reviews).
- Add Review: Users can submit a review for a specific book.
- Delete All Reviews: Users can remove all reviews for a specific book.
- Getting Started
- Prerequisites
- Project Installation
- Project Structure
- MVC Architecture Flow
- Data Flow
- Project Files Overview
This project is a basic implementation of Spring Boot's MVC architecture, using Thymeleaf as a templating engine. All the book data is stored in a JSON file, and reviews are managed dynamically.
- Java: JDK 17+
- Maven: To manage dependencies and build the project.
- Git: To clone the project.
-
Clone the Repository
git clone https://github.com/Hardvan/Spring-o-Learn.git
-
Open the project in IntelliJ IDEA.
-
Build the Project: Ensure you have Maven installed. You can build the project using:
mvn clean install
-
Run the Project: Run the Spring Boot application by going to the
SpringolearnApplication
class and clicking the green run button next to the main method. (Recommended)Alternatively, you can run the project using Maven:
mvn spring-boot:run
The app will be available on https://localhost:8090
.
The port number 8090 is configured in the
application.properties
file. You can change it to any available port.
Spring-o-Learn/
└── src/
├── main/
│ ├── java/com/hardvan/springboot/springolearn/
│ │ ├── controller/ # Controllers (MVC)
│ │ ├── model/ # Models
│ │ ├── service/ # Services
│ │ └── SpringolearnApplication.java # Main Application
│ ├── resources/
│ │ ├── templates/ # Thymeleaf HTML templates
│ │ ├── static/ # CSS and static assets
│ │ └── application.properties # App configuration
└── test/ # Test cases
The Spring-o-Learn project follows the MVC (Model-View-Controller) architecture.
-
Model: Contains the
Book
class representing a book entity with attributes like title, description, image URL, and reviews. -
View: Thymeleaf is used to render HTML pages (in
resources/templates
). Theindex.html
file displays the list of books along with forms to add or delete reviews. -
Controller:
BookController
handles HTTP requests, directing user actions to the appropriate service. It fetches data from theBookService
and passes it to the views for rendering. -
Service:
BookService
reads book data from a JSON file (books_data.json
) and contains business logic to manage reviews.
-
Client Request: Users send requests (e.g., to view books or add a review).
-
Controller: The request is handled by the
BookController
, which interacts with theBookService
for data management. -
Service Layer: The
BookService
fetches and updates the list of books and reviews stored in thebooks_data.json
file. -
Model: The data fetched or modified by the service layer is encapsulated in the
Book
class. -
View Rendering: The
Controller
adds the necessary data to theModel
, which is then passed to the Thymeleaf templates to render the UI.
- SpringolearnApplication.java: Main entry point for the Spring Boot application.
- BookController.java: Handles routes such as viewing books (
/
), adding reviews (/addReview
), and deleting reviews (/deleteAllReviews
). - Book.java: Model class that represents a book with attributes: title, image URL, description, and reviews.
- BookService.java: Service that manages books and reviews, reading data from
books_data.json
. - index.html: Thymeleaf template that displays all books, allows users to add reviews, and delete all reviews for a book.