A Spring Boot MVC application for managing authors and books in a library system.
This application demonstrates a One-to-Many relationship between Author and Book entities. An author can write multiple books, but each book is written by a single author.
- Author Management: Create, read, and update author information
- Book Management: Add, view, and manage books with their associated authors
- Data Validation: Input validation using Jakarta validation constraints
- Database Integration: MySQL database with automatic schema creation
- JSP Views: Server-side rendered views for user interface
- Test Coverage: Unit tests for services and repositories
- Framework: Spring Boot 3.2.3
- Language: Java 17
- Database: MySQL
- ORM: Hibernate/JPA
- View Engine: JSP with JSTL
- Build Tool: Maven
- Testing: JUnit 5, Mockito
src/
├── main/
│ ├── java/com/university/library/
│ │ ├── controller/ # Request handlers
│ │ ├── model/ # Entity classes
│ │ ├── repository/ # Data access layer
│ │ ├── service/ # Business logic
│ │ └── LibraryApplication # Main application
│ ├── resources/
│ │ ├── application.properties
│ │ ├── data.sql # Sample data
│ │ └── static/css/ # Stylesheets
│ └── webapp/WEB-INF/jsp/ # JSP views
└── test/
└── java/com/university/library/
├── repository/ # Repository tests
└── service/ # Service tests
Update src/main/resources/application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/library_db
spring.datasource.username=root
spring.datasource.password=root- Java 17 or higher
- Maven 3.6+
- MySQL Server
- Clone the repository:
git clone https://github.com/LaizyCoder/library-app.git
cd library-app- Build the project:
mvn clean package- Run the application:
mvn spring-boot:run- Access the application at:
http://localhost:8080
GET /authors- List all authorsGET /authors/new- Show create author formPOST /authors/save- Save/update authorGET /authors/edit/{id}- Show edit form
GET /books- List all books with authorsGET /books/new- Show create book formPOST /books/save- Save/update bookGET /books/edit/{id}- Show edit form
- One-to-Many with Book (cascade delete)
- Attributes: authorId, name, email, country
- Many-to-One with Author
- Attributes: bookId, title, genre, price, publishedDate, author
Author:
- Name: Required (NotBlank)
- Email: Required (NotBlank), Must be valid email format, Unique
Book:
- Title: Required (NotBlank)
- Price: Must be >= 0
- Published Date: Required (NotNull)
- Author: Required (NotNull)
Run tests with:
mvn testRahul
MIT