Model Layer
Here we created one POJO class for handling database operation with repository interface. The POJO class name is Book and we used one dependency that is Lombok which is available in Spring Boot. This is used for Parameterized and non-Parameterized constructors using @Data, @AllArgsConstructor, @NoArgsConstructor, @Document.
Book.java:
package com.book.inventory.app.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Represents a book entity stored in the database.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "bookdata")
public class Book {
@Id
private String id;
private String bookid;
private String title;
private String author;
private String publisher;
private String publicationYear;
private double price;
private String quantity;
private String language;
// Transient fields are not persisted in the database
@Transient
private String total;
@Transient
private String totalauthor;
@Transient
private double totalprice;
}
Book Inventory System Using Spring Boot
The Book Inventory System in Spring Boot plays an important role in Business logic. Mostly the online Book Inventory System is developed with the required business logic. Here we created a simple Spring Boot Application for the Book Inventory System, This application provides basic functionalities for understanding the Book Inventory System. Those are adding new book information, searching for book information, deleting book information, getting information about available books, and other features. For this Application, we have used Spring MVC with the Thymeleaf Java library.
Application Functionality:
In this Book Inventory System application, we provide basic functions to understand the Book Inventory System.
- Add Book: In this function, we collected book-related information by using the form in the HTML with the help of Thymeleaf. Below we provide what kind of information is collected from the book.
- id
- bookid
- title
- author
- publisher
- publicationYear
- price
- quantity
- language
- total
- totalauthor
- totalprice
- Delete Book: In this function, we can delete unwanted book information by using bookid and below we provide the related logic below with output.
- Search Book: In this function, we can search book information by using bookid and below we provide the related logic below with output.
- Book Info: This is special function in this application, In this function It will show book details with It’s availability.
Prerequisites:
- Spring Boot Framework
- Thymeleaf
- MongoDB
- Spring MVC Pattern
- Bootstrap Framework
- Project Type is Gradle
- Spring Tool Suite IDE (STS)
Gradle Dependencies:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Contact Us