This page is generated from the following source files:
This document provides a comprehensive architectural analysis of the BookManager2 system, a Spring Boot-based library management application. The system implements a classic three-tier architecture with clear separation between presentation, business logic, and data access layers.
The project is built on a mature Java technology stack designed for enterprise web applications. The core framework and dependencies are defined in the Maven configuration.
| Technology | Version | Purpose | Selection Rationale |
|---|---|---|---|
| Spring Boot | 2.5.6 | Core framework | Rapid development, auto-configuration, embedded server |
| MyBatis | 2.0.0 | ORM framework | SQL flexibility, fine-grained control over queries |
| MySQL | - | Primary database | Relational data model, ACID compliance |
| Redis | - | Caching layer | Session storage, performance optimization |
| Maven | - | Build tool | Dependency management, build lifecycle |
| Java | 1.8 | Runtime platform | Enterprise compatibility, LTS support |
The pom.xml:1-82 file defines all project dependencies including the Spring Boot starter web, MyBatis integration, Redis support, and MySQL connector. The configuration also includes the MyBatis generator plugin for reverse engineering database schemas into Java entities and mappers.
The MyBatis framework provides the data persistence layer, with mapper interfaces defining database operations. The src/main/java/com/wangpeng/bms/mapper/BookInfoMapper.java:8-35 demonstrates the standard CRUD operations pattern including selectByPrimaryKey, insertSelective, updateByPrimaryKeySelective, and custom query methods for pagination and search functionality.
The system follows a strict layered architecture pattern with well-defined boundaries between components. Each layer has specific responsibilities and communicates only with adjacent layers.
正在加载图表渲染器...
The controller layer handles HTTP request routing and response formatting. Controllers are annotated with @RestController and @RequestMapping to define REST endpoints. The src/main/java/com/wangpeng/bms/web/BookInfoController.java:61-64 shows a typical update endpoint that receives a BookInfo object via @RequestBody and delegates to the service layer.
Key responsibilities:
The service layer encapsulates business logic and transaction management. Services implement interfaces and are annotated with @Service. The src/main/java/com/wangpeng/bms/service/impl/BookInfoServiceImpl.java:69-73 demonstrates the delegation pattern where the service method calls the mapper's updateByPrimaryKeySelective method, which only updates non-null fields.
MyBatis mappers define database operations through Java interfaces paired with XML mapping files. The src/main/java/com/wangpeng/bms/mapper/BookInfoMapper.java:8-35 interface declares methods for:
selectByPrimaryKey, deleteByPrimaryKeyinsertSelective, updateByPrimaryKeySelectiveselectAll, selectAllByLimitselectBySearch, selectCountBySearchThe security architecture implements a session-based authentication pattern with configurable path-based access control. The interceptor configuration defines which URLs require authentication and which are publicly accessible.
正在加载图表渲染器...
The src/main/java/com/wangpeng/bms/config/InterceptorConfig.java:10-61 class implements WebMvcConfigurer to register interceptors. The configuration defines three path categories:
all array): All HTML pages and API endpoints under /bookInfo/**, /bookType/**, /borrow/**, /update/**, /user/**aboutLogin array): Root path, index.html, register.html, login and registration endpointsaboutReader array): Reader-specific pages and requestsThe interceptor registration is currently commented out in the configuration, indicating the system may be in development mode or using alternative security mechanisms.
The src/main/java/com/wangpeng/bms/interceptor/UserInterceptor.java:10-26 implements HandlerInterceptor to validate user sessions. The preHandle method:
userObj attribute from the HTTP sessiontrue if the user is authenticated, allowing the request to proceed/index.html and returns false if no user is found in sessionThe system implements transactional business operations to ensure data consistency across multiple database tables. The borrowing workflow demonstrates the transaction management pattern.
The src/main/java/com/wangpeng/bms/web/BorrowController.java:67-106 implements the book borrowing logic with the @Transactional annotation. The operation performs:
isborrowed statusNotEnoughException if book is already borrowedisborrowed flag to 1The transaction includes manual rollback handling via TransactionAspectSupport.currentTransactionStatus().setRollbackOnly() when exceptions occur, ensuring atomicity of the multi-step operation.
The src/main/java/com/wangpeng/bms/web/UpdateController.java:21-88 manages file uploads for book cover images. The implementation:
static directory path using ResourceUtils.getURL("classpath:")ServletFileUploadThe upload endpoint at /updateImg accepts multipart form data and stores files in the pictures subdirectory under static resources.
The following sequence diagram illustrates the end-to-end flow of a book update operation, showing the interaction between layers.
正在加载图表渲染器...
The sequence diagram is based on the following code evidence:
The following diagram illustrates the dependency relationships between core modules in the system.
正在加载图表渲染器...
The project chose MyBatis for data persistence instead of JPA/Hibernate. This decision provides:
The trade-off is increased boilerplate code and manual mapping maintenance.
The system uses HTTP session storage for user authentication rather than JWT tokens. This approach:
The limitation is reduced scalability for distributed deployments requiring session replication.
The mapper methods insertSelective and updateByPrimaryKeySelective only modify non-null fields. This pattern:
Evidence: src/main/java/com/wangpeng/bms/mapper/BookInfoMapper.java:8-35 shows both selective and full update methods.
The borrowing operation implements manual rollback via TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(). This approach:
Evidence: src/main/java/com/wangpeng/bms/web/BorrowController.java:67-106 shows the try-catch block with manual rollback.
Uploaded files are stored in the application's static resources directory rather than external storage. This design:
The limitation is lack of scalability for distributed deployments and potential issues with containerized deployments where the static directory may not persist.
The interceptor registration in InterceptorConfig is commented out, suggesting:
Evidence: src/main/java/com/wangpeng/bms/config/InterceptorConfig.java:10-61 shows commented registry.addInterceptor() calls.
The frontend is pre-built and served as static JavaScript files from src/main/resources/static/. This architecture:
Evidence: src/main/resources/static/static/js/app.3082c59a.js:1-1 contains the compiled Vue.js application.
The application follows Spring Boot conventions for configuration and startup:
BookManagerApplication serves as the entry point with @SpringBootApplication annotationapplication.properties or application.yml (需要确认: configuration file not provided in source files)com.wangpeng.bms package@MapperScan or individual @Mapper annotations (需要确认: scanner configuration not visible in provided files)The pom.xml:1-82 defines resource handling to include XML mapper files:
**/*.xml for MyBatis mapper filesThe Maven wrapper (.mvn/wrapper/MavenWrapperDownloader.java:1-118) ensures consistent Maven versions across development environments.
Hardcoded URL in File Upload: The UpdateController returns a hardcoded localhost URL (http://localhost:8092/BookManager/), which will break in production environments. Evidence: src/main/java/com/wangpeng/bms/web/UpdateController.java:21-88
Console Logging: Error handling uses System.out.println() and e.printStackTrace() instead of proper logging frameworks. Evidence: src/main/java/com/wangpeng/bms/web/BorrowController.java:67-106
Disabled Security: The interceptor configuration is commented out, potentially leaving endpoints unprotected. Evidence: src/main/java/com/wangpeng/bms/config/InterceptorConfig.java:10-61
No Input Validation: Controllers lack explicit input validation annotations (@Valid, @NotNull), relying on frontend validation. Evidence: src/main/java/com/wangpeng/bms/web/BookInfoController.java:61-64