Files
2026-04-27 18:40:30 +08:00

2.7 KiB

Directory Structure

Backend directory organization for the JSP + Servlet + MySQL application.


Overview

Future backend code should follow the established B/S layered architecture. There is no application source tree yet; the paths and package names below are illustrative conventions to use when creating the first application code.


Suggested Layout

src/main/java/com/mzh/library/
  controller/       Servlet controllers such as BookServlet
  service/          Service interfaces such as BookService
  service/impl/     Business implementations such as BookServiceImpl
  dao/              DAO interfaces such as BookDao
  dao/impl/         MySQL DAO implementations such as BookDaoImpl
  entity/           JavaBeans/entities such as Book, Reader, BorrowRecord
  filter/           Authentication, authorization, encoding filters
  util/             Shared utilities such as JdbcUtil or DateUtil
src/main/resources/
  db.properties     MySQL connection configuration when introduced
src/main/webapp/
  WEB-INF/web.xml   Servlet/filter mappings when annotations are not used

Use the package root consistently once the first code is created. If a different root package is chosen in IDEA, update this spec in the same change.


Layer Responsibilities

  • controller: Servlet classes dispatch requests, validate parameters, call services, choose JSP forwards or redirects, and return results.
  • service: Business workflows including book warehousing/intake, borrowing, returning, renewals, inventory status updates, overdue statistics, and permission checks.
  • dao: CRUD and query access to MySQL. DAOs should not perform presentation rendering or multi-step business workflows.
  • entity: Plain data objects representing books, categories, readers, borrowing records, administrators, roles/permissions, and system logs.
  • filter: Cross-cutting web concerns such as login checks, role guards, and request encoding.
  • util: Small shared helpers only after searching for existing helpers first.

Naming Conventions

  • Servlet controllers use names such as BookServlet, ReaderServlet, BorrowServlet, and LoginServlet.
  • Service interfaces and implementations use names such as BookService and BookServiceImpl.
  • DAO interfaces and implementations use names such as BookDao and BookDaoImpl.
  • Entity names should be singular Java nouns such as Book, BookCategory, Reader, BorrowRecord, Administrator, RolePermission, and SystemLog.

Boundaries

Do not put SQL in JSPs or Servlets. Do not put HTML generation in DAOs or services. Keep permission checks in filters/services and keep request parameter parsing in controllers.