新增书籍表、列表/搜索、管理员/馆员维护入口

This commit is contained in:
Zzzz
2026-04-27 19:49:14 +08:00
parent 8777efa21d
commit 763830f767
28 changed files with 2392 additions and 8 deletions
@@ -0,0 +1,109 @@
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Catalog - MZH Library</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/app.css">
</head>
<body>
<%@ include file="/WEB-INF/jsp/common/header.jspf" %>
<main class="page-shell">
<section class="dashboard-hero catalog-hero" aria-labelledby="catalog-title">
<p class="eyebrow">Catalog</p>
<h1 id="catalog-title">Book catalog</h1>
<p>Search the library collection by identifier, title, author, or category.</p>
</section>
<c:if test="${not empty errorMessage}">
<div class="message message-error" role="alert">
<c:out value="${errorMessage}" />
</div>
</c:if>
<section class="toolbar-panel" aria-label="Catalog search">
<form class="search-form" action="${pageContext.request.contextPath}/catalog" method="get">
<div class="search-field">
<label for="identifier">Book ID</label>
<input id="identifier" name="identifier" type="text" value="${fn:escapeXml(criteria.identifier)}">
</div>
<div class="search-field">
<label for="title">Title</label>
<input id="title" name="title" type="text" value="${fn:escapeXml(criteria.title)}">
</div>
<div class="search-field">
<label for="author">Author</label>
<input id="author" name="author" type="text" value="${fn:escapeXml(criteria.author)}">
</div>
<div class="search-field">
<label for="categoryId">Category</label>
<select id="categoryId" name="categoryId">
<option value="">All categories</option>
<c:forEach var="category" items="${categories}">
<option value="${category.id}" <c:if test="${criteria.categoryId == category.id}">selected</c:if>>
<c:out value="${category.name}" />
</option>
</c:forEach>
</select>
<c:if test="${not empty errors.categoryId}">
<span class="field-error"><c:out value="${errors.categoryId}" /></span>
</c:if>
</div>
<button class="button button-primary" type="submit">Search</button>
<a class="button button-secondary" href="${pageContext.request.contextPath}/catalog">Clear</a>
<c:if test="${canManageBooks}">
<a class="button button-secondary" href="${pageContext.request.contextPath}/books">Manage books</a>
</c:if>
</form>
</section>
<section class="table-panel" aria-labelledby="catalog-results-title">
<h2 id="catalog-results-title">Results</h2>
<c:choose>
<c:when test="${empty books}">
<p class="empty-state">No books match the current filters.</p>
</c:when>
<c:otherwise>
<div class="table-scroll">
<table class="data-table">
<thead>
<tr>
<th scope="col">Book ID</th>
<th scope="col">Title</th>
<th scope="col">Author</th>
<th scope="col">Category</th>
<th scope="col">Copies</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
<c:forEach var="book" items="${books}">
<tr>
<td><c:out value="${book.identifier}" /></td>
<td><c:out value="${book.title}" /></td>
<td><c:out value="${book.author}" /></td>
<td><c:out value="${book.categoryName}" /></td>
<td><c:out value="${book.availableCopies}" /> / <c:out value="${book.totalCopies}" /></td>
<td>
<span class="status-pill status-${book.status.code}">
<c:out value="${book.status.displayName}" />
</span>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</c:otherwise>
</c:choose>
</section>
</main>
</body>
</html>
+119
View File
@@ -0,0 +1,119 @@
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><c:out value="${formTitle}" /> - MZH Library</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/app.css">
</head>
<body>
<%@ include file="/WEB-INF/jsp/common/header.jspf" %>
<main class="page-shell">
<section class="form-panel" aria-labelledby="book-form-title">
<p class="eyebrow">Book Management</p>
<h1 id="book-form-title"><c:out value="${formTitle}" /></h1>
<c:if test="${not empty errorMessage}">
<div class="message message-error" role="alert">
<c:out value="${errorMessage}" />
</div>
</c:if>
<c:set var="hasFormValues" value="${not empty formValues}" />
<c:set var="identifierValue" value="${hasFormValues ? formValues.identifier : book.identifier}" />
<c:set var="titleValue" value="${hasFormValues ? formValues.title : book.title}" />
<c:set var="authorValue" value="${hasFormValues ? formValues.author : book.author}" />
<c:set var="categoryValue" value="${book.categoryId}" />
<c:set var="totalCopiesValue" value="${hasFormValues ? formValues.totalCopies : book.totalCopies}" />
<c:set var="availableCopiesValue" value="${hasFormValues ? formValues.availableCopies : book.availableCopies}" />
<c:set var="statusValue" value="${hasFormValues ? formValues.status : book.status.code}" />
<form class="book-form" action="${pageContext.request.contextPath}${formAction}" method="post" novalidate>
<c:if test="${book.id > 0}">
<input type="hidden" name="id" value="${book.id}">
</c:if>
<div class="form-grid">
<div class="form-field">
<label for="identifier">Book ID</label>
<input id="identifier" name="identifier" type="text" value="${fn:escapeXml(identifierValue)}" required>
<c:if test="${not empty errors.identifier}">
<span class="field-error"><c:out value="${errors.identifier}" /></span>
</c:if>
</div>
<div class="form-field">
<label for="title">Title</label>
<input id="title" name="title" type="text" value="${fn:escapeXml(titleValue)}" required>
<c:if test="${not empty errors.title}">
<span class="field-error"><c:out value="${errors.title}" /></span>
</c:if>
</div>
<div class="form-field">
<label for="author">Author</label>
<input id="author" name="author" type="text" value="${fn:escapeXml(authorValue)}" required>
<c:if test="${not empty errors.author}">
<span class="field-error"><c:out value="${errors.author}" /></span>
</c:if>
</div>
<div class="form-field">
<label for="categoryId">Category</label>
<select id="categoryId" name="categoryId" required>
<option value="">Select category</option>
<c:forEach var="category" items="${categories}">
<option value="${category.id}" <c:if test="${categoryValue == category.id}">selected</c:if>>
<c:out value="${category.name}" />
</option>
</c:forEach>
</select>
<c:if test="${not empty errors.categoryId}">
<span class="field-error"><c:out value="${errors.categoryId}" /></span>
</c:if>
</div>
<div class="form-field">
<label for="totalCopies">Total copies</label>
<input id="totalCopies" name="totalCopies" type="number" min="0" value="${fn:escapeXml(totalCopiesValue)}" required>
<c:if test="${not empty errors.totalCopies}">
<span class="field-error"><c:out value="${errors.totalCopies}" /></span>
</c:if>
</div>
<div class="form-field">
<label for="availableCopies">Available copies</label>
<input id="availableCopies" name="availableCopies" type="number" min="0" value="${fn:escapeXml(availableCopiesValue)}" required>
<c:if test="${not empty errors.availableCopies}">
<span class="field-error"><c:out value="${errors.availableCopies}" /></span>
</c:if>
</div>
<div class="form-field">
<label for="status">Status</label>
<select id="status" name="status" required>
<option value="">Select status</option>
<c:forEach var="status" items="${statuses}">
<option value="${status.code}" <c:if test="${statusValue == status.code}">selected</c:if>>
<c:out value="${status.displayName}" />
</option>
</c:forEach>
</select>
<c:if test="${not empty errors.status}">
<span class="field-error"><c:out value="${errors.status}" /></span>
</c:if>
</div>
</div>
<div class="form-actions">
<button class="button button-primary" type="submit">Save</button>
<a class="button button-secondary" href="${pageContext.request.contextPath}/books">Cancel</a>
</div>
</form>
</section>
</main>
</body>
</html>
@@ -0,0 +1,126 @@
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Manage Books - MZH Library</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/app.css">
</head>
<body>
<%@ include file="/WEB-INF/jsp/common/header.jspf" %>
<main class="page-shell">
<section class="dashboard-hero catalog-hero" aria-labelledby="manage-title">
<p class="eyebrow">Book Management</p>
<h1 id="manage-title">Manage books</h1>
<p>Create, update, delete, and review inventory for catalog records.</p>
<a class="button button-primary" href="${pageContext.request.contextPath}/books/new">New book</a>
</section>
<c:if test="${not empty successMessage}">
<div class="message message-success" role="status">
<c:out value="${successMessage}" />
</div>
</c:if>
<c:if test="${not empty errorMessage}">
<div class="message message-error" role="alert">
<c:out value="${errorMessage}" />
</div>
</c:if>
<section class="toolbar-panel" aria-label="Book management search">
<form class="search-form" action="${pageContext.request.contextPath}/books" method="get">
<div class="search-field">
<label for="identifier">Book ID</label>
<input id="identifier" name="identifier" type="text" value="${fn:escapeXml(criteria.identifier)}">
</div>
<div class="search-field">
<label for="title">Title</label>
<input id="title" name="title" type="text" value="${fn:escapeXml(criteria.title)}">
</div>
<div class="search-field">
<label for="author">Author</label>
<input id="author" name="author" type="text" value="${fn:escapeXml(criteria.author)}">
</div>
<div class="search-field">
<label for="categoryId">Category</label>
<select id="categoryId" name="categoryId">
<option value="">All categories</option>
<c:forEach var="category" items="${categories}">
<option value="${category.id}" <c:if test="${criteria.categoryId == category.id}">selected</c:if>>
<c:out value="${category.name}" />
</option>
</c:forEach>
</select>
<c:if test="${not empty errors.categoryId}">
<span class="field-error"><c:out value="${errors.categoryId}" /></span>
</c:if>
</div>
<button class="button button-primary" type="submit">Search</button>
<a class="button button-secondary" href="${pageContext.request.contextPath}/books">Clear</a>
<a class="button button-secondary" href="${pageContext.request.contextPath}/catalog">View catalog</a>
</form>
</section>
<section class="table-panel" aria-labelledby="management-results-title">
<h2 id="management-results-title">Book records</h2>
<c:choose>
<c:when test="${empty books}">
<p class="empty-state">No book records match the current filters.</p>
</c:when>
<c:otherwise>
<div class="table-scroll">
<table class="data-table">
<thead>
<tr>
<th scope="col">Book ID</th>
<th scope="col">Title</th>
<th scope="col">Author</th>
<th scope="col">Category</th>
<th scope="col">Copies</th>
<th scope="col">Status</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<c:forEach var="book" items="${books}">
<tr>
<td><c:out value="${book.identifier}" /></td>
<td><c:out value="${book.title}" /></td>
<td><c:out value="${book.author}" /></td>
<td><c:out value="${book.categoryName}" /></td>
<td><c:out value="${book.availableCopies}" /> / <c:out value="${book.totalCopies}" /></td>
<td>
<span class="status-pill status-${book.status.code}">
<c:out value="${book.status.displayName}" />
</span>
</td>
<td>
<div class="table-actions">
<a class="button button-secondary"
href="${pageContext.request.contextPath}/books/edit?id=${book.id}">Edit</a>
<form action="${pageContext.request.contextPath}/books/delete"
method="post"
onsubmit="return confirm('Delete this book record?');">
<input type="hidden" name="id" value="${book.id}">
<button class="button button-danger" type="submit">Delete</button>
</form>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</c:otherwise>
</c:choose>
</section>
</main>
</body>
</html>
@@ -4,11 +4,13 @@
<c:if test="${not empty sessionScope.authenticatedUser}">
<nav class="top-nav" aria-label="Primary">
<a href="${pageContext.request.contextPath}/dashboard">Dashboard</a>
<a href="${pageContext.request.contextPath}/catalog">Catalog</a>
<c:if test="${sessionScope.userRole == 'administrator'}">
<a href="${pageContext.request.contextPath}/admin/home">Admin</a>
</c:if>
<c:if test="${sessionScope.userRole == 'administrator' or sessionScope.userRole == 'librarian'}">
<a href="${pageContext.request.contextPath}/librarian/home">Librarian</a>
<a href="${pageContext.request.contextPath}/books">Books</a>
</c:if>
<a href="${pageContext.request.contextPath}/reader/home">Reader</a>
<span class="user-pill">
+13 -1
View File
@@ -34,11 +34,23 @@
<p>Book, reader, borrowing, return, renewal, and overdue entry point.</p>
<a class="button button-secondary" href="${pageContext.request.contextPath}/librarian/home">Open</a>
</article>
<article class="workspace-card">
<h2>Book Management</h2>
<p>Create, update, delete, and review book inventory records.</p>
<a class="button button-secondary" href="${pageContext.request.contextPath}/books">Open</a>
</article>
</c:if>
<article class="workspace-card">
<h2>Book Catalog</h2>
<p>Search books by title, author, category, or book identifier.</p>
<a class="button button-secondary" href="${pageContext.request.contextPath}/catalog">Search</a>
</article>
<article class="workspace-card">
<h2>Reader Center</h2>
<p>Catalog search and reader self-service entry point.</p>
<p>Reader self-service entry point.</p>
<a class="button button-secondary" href="${pageContext.request.contextPath}/reader/home">Open</a>
</article>
</section>
+16
View File
@@ -19,6 +19,22 @@
<p><c:out value="${areaSummary}" /></p>
<a class="button button-primary" href="${pageContext.request.contextPath}/dashboard">Back to dashboard</a>
</section>
<section class="card-grid role-actions" aria-label="Workspace actions">
<article class="workspace-card">
<h2>Book Catalog</h2>
<p>Search available collection records by title, author, category, or book identifier.</p>
<a class="button button-secondary" href="${pageContext.request.contextPath}/catalog">Search catalog</a>
</article>
<c:if test="${sessionScope.userRole == 'administrator' or sessionScope.userRole == 'librarian'}">
<article class="workspace-card">
<h2>Book Management</h2>
<p>Create, update, delete, and review inventory fields for book records.</p>
<a class="button button-secondary" href="${pageContext.request.contextPath}/books">Manage books</a>
</article>
</c:if>
</section>
</main>
</body>
</html>
+22
View File
@@ -75,6 +75,28 @@
<url-pattern>/reader/home</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>BookCatalogServlet</servlet-name>
<servlet-class>com.mzh.library.controller.BookCatalogServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BookCatalogServlet</servlet-name>
<url-pattern>/catalog</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>BookManagementServlet</servlet-name>
<servlet-class>com.mzh.library.controller.BookManagementServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BookManagementServlet</servlet-name>
<url-pattern>/books</url-pattern>
<url-pattern>/books/new</url-pattern>
<url-pattern>/books/edit</url-pattern>
<url-pattern>/books/update</url-pattern>
<url-pattern>/books/delete</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>UnauthorizedServlet</servlet-name>
<servlet-class>com.mzh.library.controller.UnauthorizedServlet</servlet-class>
+197 -2
View File
@@ -8,6 +8,8 @@
--color-primary: #256f6c;
--color-primary-strong: #1b5654;
--color-accent: #b54238;
--color-success: #2f6f3e;
--color-warning: #8a5a00;
--shadow-panel: 0 18px 45px rgba(28, 39, 49, 0.12);
}
@@ -91,7 +93,10 @@ a {
.login-panel,
.notice-panel,
.dashboard-hero,
.workspace-card {
.workspace-card,
.toolbar-panel,
.table-panel,
.form-panel {
border: 1px solid var(--color-border);
border-radius: 8px;
background: var(--color-panel);
@@ -184,6 +189,15 @@ h2 {
background: #ffffff;
}
.button-danger {
color: #ffffff;
background: var(--color-accent);
}
.button-danger:hover {
background: #8f3028;
}
.message {
margin-bottom: 16px;
padding: 10px 12px;
@@ -197,6 +211,12 @@ h2 {
background: #fff0ee;
}
.message-success {
color: #1f572e;
border: 1px solid rgba(47, 111, 62, 0.3);
background: #effaf1;
}
.page-shell {
padding: 36px 0 56px;
}
@@ -239,6 +259,173 @@ h2 {
padding: 28px;
}
.role-actions {
margin-top: 24px;
}
.catalog-hero {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
flex-wrap: wrap;
}
.catalog-hero .button {
margin-top: 0;
}
.toolbar-panel,
.table-panel,
.form-panel {
padding: 24px;
margin-bottom: 24px;
}
.search-form {
display: grid;
grid-template-columns: repeat(4, minmax(120px, 1fr)) auto auto auto;
gap: 10px;
align-items: end;
}
.search-field {
display: grid;
gap: 6px;
}
.search-form label {
color: var(--color-muted);
font-size: 13px;
font-weight: 700;
}
.search-form input,
.search-form select,
.book-form input,
.book-form select {
width: 100%;
min-height: 42px;
padding: 9px 11px;
border: 1px solid var(--color-border);
border-radius: 6px;
background: #ffffff;
font: inherit;
}
.search-form input:focus,
.search-form select:focus,
.book-form input:focus,
.book-form select:focus {
outline: 3px solid rgba(37, 111, 108, 0.18);
border-color: var(--color-primary);
}
.table-scroll {
width: 100%;
overflow-x: auto;
}
.data-table {
width: 100%;
min-width: 760px;
border-collapse: collapse;
font-size: 14px;
}
.data-table th,
.data-table td {
padding: 12px 10px;
text-align: left;
border-bottom: 1px solid var(--color-border);
vertical-align: middle;
}
.data-table th {
color: var(--color-muted);
font-size: 13px;
font-weight: 700;
background: #f8fafc;
}
.empty-state {
margin-bottom: 0;
color: var(--color-muted);
}
.status-pill {
display: inline-flex;
min-height: 28px;
align-items: center;
padding: 4px 9px;
border-radius: 999px;
font-size: 12px;
font-weight: 700;
}
.status-available {
color: var(--color-success);
background: #edf8ef;
}
.status-unavailable {
color: var(--color-warning);
background: #fff7e5;
}
.status-archived {
color: var(--color-muted);
background: #eef1f5;
}
.table-actions {
display: flex;
gap: 8px;
align-items: center;
flex-wrap: wrap;
}
.table-actions form {
margin: 0;
}
.form-panel {
max-width: 860px;
}
.book-form {
display: grid;
gap: 20px;
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16px;
}
.form-field {
display: grid;
gap: 6px;
}
.form-field label {
color: var(--color-muted);
font-size: 14px;
font-weight: 700;
}
.field-error {
color: #7a211a;
font-size: 13px;
}
.form-actions {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
@media (max-width: 720px) {
.app-header {
align-items: flex-start;
@@ -257,7 +444,15 @@ h2 {
.login-panel,
.notice-panel,
.dashboard-hero,
.workspace-card {
.workspace-card,
.toolbar-panel,
.table-panel,
.form-panel {
box-shadow: none;
}
.search-form,
.form-grid {
grid-template-columns: 1fr;
}
}