A comprehensive Spring Boot application for managing books and authors with full CRUD operations, custom JPQL queries, and JSP-based UI.
This application demonstrates a complete Spring Boot implementation with:
- Entity Management: Books and Authors with One-to-Many relationship
- CRUD Operations: Create, Read, and Update operations for both entities
- Custom Queries: INNER JOIN queries using JPQL
- JSP Views: Beautiful, responsive UI with CSS styling
- Exception Handling: Proper validation and error handling
- Unit Testing: Comprehensive tests using JUnit and Mockito
- ✅ Create new authors with validation
- ✅ View all authors in a list
- ✅ View individual author details with their books
- ✅ Update author information
- ✅ Delete authors
- ✅ Duplicate email detection
- ✅ Create new books with author association
- ✅ View all books in a list
- ✅ View individual book details with author information
- ✅ Update book information
- ✅ Delete books
- ✅ Duplicate ISBN detection
- ✅ INNER JOIN query to display books with author details
- ✅ Filter books by author nationality
- ✅ Filter books by genre with author details
Author (1) -------- (N) Book
Author:
- id (PK)
- name
- email (unique)
- bio
- nationality
Book:
- id (PK)
- title
- isbn (unique)
- publicationYear
- price
- genre
- author_id (FK)
- Framework: Spring Boot 3.1.5
- Java: 17
- Database: MySQL 8.0
- ORM: Spring Data JPA (Hibernate)
- View Layer: JSP with JSTL
- Build Tool: Maven
- Testing: JUnit 5, Mockito, AssertJ
- Styling: CSS3
- Validation: Jakarta Bean Validation
book-author-management/
├── src/
│ ├── main/
│ │ ├── java/com/library/bookauthor/
│ │ │ ├── controller/ # MVC Controllers
│ │ │ │ ├── AuthorController.java
│ │ │ │ ├── BookController.java
│ │ │ │ └── HomeController.java
│ │ │ ├── entity/ # JPA Entities
│ │ │ │ ├── Author.java
│ │ │ │ └── Book.java
│ │ │ ├── repository/ # Data Access Layer
│ │ │ │ ├── AuthorRepository.java
│ │ │ │ └── BookRepository.java
│ │ │ ├── service/ # Business Logic
│ │ │ │ ├── AuthorService.java
│ │ │ │ └── BookService.java
│ │ │ ├── dto/ # Data Transfer Objects
│ │ │ │ └── BookAuthorDTO.java
│ │ │ ├── exception/ # Custom Exceptions
│ │ │ │ ├── ResourceNotFoundException.java
│ │ │ │ └── DuplicateResourceException.java
│ │ │ └── BookAuthorManagementApplication.java
│ │ ├── resources/
│ │ │ ├── application.properties
│ │ │ ├── data.sql # Sample data
│ │ │ └── static/css/
│ │ │ └── style.css
│ │ └── webapp/WEB-INF/views/ # JSP Views
│ │ ├── home.jsp
│ │ ├── author/
│ │ │ ├── list.jsp
│ │ │ ├── form.jsp
│ │ │ └── view.jsp
│ │ └── book/
│ │ ├── list.jsp
│ │ ├── form.jsp
│ │ ├── view.jsp
│ │ └── list-with-authors.jsp
│ └── test/ # Unit Tests
│ └── java/com/library/bookauthor/
│ ├── repository/
│ │ ├── AuthorRepositoryTest.java
│ │ └── BookRepositoryTest.java
│ └── service/
│ ├── AuthorServiceTest.java
│ └── BookServiceTest.java
└── pom.xml
- Java 17 or higher
- MySQL 8.0 or higher
- Maven 3.6 or higher
- Create MySQL database:
CREATE DATABASE library_db;- Update
src/main/resources/application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/library_db
spring.datasource.username=YOUR_USERNAME
spring.datasource.password=YOUR_PASSWORD- Clone the repository
- Navigate to project directory
- Build the project:
mvn clean install- Run the application:
mvn spring-boot:run- Access the application:
http://localhost:8080
mvn testThe application comes with 10 sample authors and 10 sample books pre-populated in the database through data.sql.
The application features a modern, responsive design with:
- Gradient headers
- Card-based layouts
- Hover effects and animations
- Mobile-responsive tables
- Color-coded buttons
- Alert messages for user feedback
GET /authors- List all authorsGET /authors/new- Show create author formPOST /authors- Create new authorGET /authors/{id}- View author detailsGET /authors/edit/{id}- Show edit author formPOST /authors/{id}- Update authorGET /authors/delete/{id}- Delete author
GET /books- List all booksGET /books/with-authors- List books with authors (INNER JOIN)GET /books/new- Show create book formPOST /books- Create new bookGET /books/{id}- View book detailsGET /books/edit/{id}- Show edit book formPOST /books/{id}- Update bookGET /books/delete/{id}- Delete book
@Query("SELECT new com.library.bookauthor.dto.BookAuthorDTO(" +
"b.id, b.title, b.isbn, b.publicationYear, b.price, b.genre, " +
"a.id, a.name, a.email, a.nationality) " +
"FROM Book b INNER JOIN b.author a")
List<BookAuthorDTO> findAllBooksWithAuthors();This query demonstrates:
- JPQL INNER JOIN syntax
- Constructor expression for DTO
- Combining data from multiple entities
- Type-safe query results
- Repository Layer: Tests for custom queries, CRUD operations
- Service Layer: Business logic testing with Mockito
- Test Types: Unit tests, integration tests
- Assertions: Using AssertJ for fluent assertions
ResourceNotFoundException: When entity is not foundDuplicateResourceException: For unique constraint violations- Form validation errors with user-friendly messages
- Database integrity constraint handling
Created as a Spring Boot assignment demonstrating full-stack Java development skills.
This project is created for educational purposes.