培訓管理子系統開發4
整個項目預期的任務量 (任務量 = 所有工作的預期時間10天)和 目前已經花的時間 (所有記錄的 ‘已經花費的時間’4天),還剩余的時間(所有工作的 ‘剩余時間’6天)


實現了試卷管理試卷的發布與瀏覽


package com.example.training.entity;
import javax.persistence.*;
@Entity
public class ExamPaper {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
@Column(columnDefinition = "TEXT")
private String content;
private String answer;
private String score;
public ExamPaper() {
}
public ExamPaper(Integer id, String name, String content, String answer, String score) {
this.id = id;
this.name = name;
this.content = content;
this.answer = answer;
this.score = score;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public String getScore() {
return score;
}
public void setScore(String score) {
this.score = score;
}
}
// 試卷管理
@GetMapping("/papers")
public String paperManage(HttpSession session, Model model) {
if (!checkAdmin(session)) return "redirect:/login";
model.addAttribute("papers", adminService.findAllExamPapers());
return "admin/paper";
}
@PostMapping("/papers")
public String savePaper(@ModelAttribute ExamPaper paper, HttpSession session) {
if (!checkAdmin(session)) return "redirect:/login";
adminService.saveExamPaper(paper);
return "redirect:/admin/papers";
}
@PostMapping("/papers/delete/{id}")
public String deletePaper(@PathVariable Integer id,
HttpSession session,
RedirectAttributes ra) {
if (!checkAdmin(session)) return "redirect:/login";
try {
adminService.deleteExamPaper(id);
ra.addFlashAttribute("success", "刪除試卷成功");
} catch (Exception e) {
ra.addFlashAttribute("error", "刪除失敗:" + e.getMessage());
}
return "redirect:/admin/papers";
}
@PostMapping("/papers/score/{id}")
public String updateScore(@PathVariable Integer id,
@RequestParam String score,
HttpSession session) {
if (!checkAdmin(session)) return "redirect:/login";
adminService.updateExamScore(id, score);
return "redirect:/admin/papers";
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>試卷管理</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* 基礎樣式 */
body {
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
margin: 0;
min-height: 100vh;
padding: 2rem;
}
.admin-container {
background: rgba(255, 255, 255, 0.98);
border-radius: 16px;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
padding: 2.5rem;
max-width: 1200px;
margin: 0 auto;
backdrop-filter: blur(8px);
}
/* 提示信息 */
.alert-container {
position: fixed;
top: 20px;
right: 20px;
max-width: 400px;
z-index: 1000;
}
.alert {
padding: 1rem 1.5rem;
border-radius: 8px;
margin-bottom: 1rem;
font-weight: 500;
transition: opacity 0.5s ease;
}
.alert.success {
background: #e8f6ef;
color: #2e7d32;
border: 1px solid #a5d6a7;
}
.alert.error {
background: #ffebee;
color: #c62828;
border: 1px solid #ffcdd2;
}
/* 返回鏈接 */
.back-link {
display: inline-flex;
align-items: center;
gap: 0.5rem;
color: #2a5298;
padding: 0.8rem 1.2rem;
border-radius: 6px;
background: rgba(42,82,152,0.1);
transition: all 0.2s ease;
text-decoration: none;
margin-bottom: 2rem;
}
.back-link:hover {
background: rgba(42,82,152,0.2);
transform: translateX(-3px);
}
/* 標題樣式 */
h2 {
color: #1e3c72;
margin: 0 0 2rem;
padding-bottom: 1rem;
border-bottom: 3px solid #1e3c72;
font-size: 2rem;
letter-spacing: -0.5px;
}
/* 表單樣式 */
form {
background: #f8f9fa;
padding: 2rem;
border-radius: 12px;
margin-bottom: 3rem;
}
input, textarea {
width: 100%;
padding: 12px;
margin: 10px 0;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 1rem;
transition: all 0.3s ease;
}
input:focus, textarea:focus {
border-color: #1e3c72;
box-shadow: 0 0 0 3px rgba(30,60,114,0.1);
outline: none;
}
button[type="submit"] {
background: #1e3c72;
color: white;
padding: 12px 24px;
border: none;
border-radius: 8px;
cursor: pointer;
font-weight: 600;
transition: all 0.2s ease;
margin-top: 1rem;
}
button[type="submit"]:hover {
background: #2a5298;
transform: translateY(-2px);
}
/* 表格樣式 */
.paper-table {
width: 100%;
border-collapse: collapse;
background: white;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
th {
background: linear-gradient(135deg, #1e3c72, #2a5298);
color: white;
padding: 1rem;
font-weight: 600;
text-align: left;
}
td {
padding: 1rem;
border-bottom: 1px solid #f0f4f8;
vertical-align: top;
}
.content-cell div {
max-height: 100px;
overflow-y: auto;
line-height: 1.6;
}
tr:hover {
background-color: #f8fafc;
}
/* 刪除按鈕 */
.delete-btn {
background: #c62828 !important;
color: white !important;
padding: 8px 16px;
border-radius: 6px;
border: none;
cursor: pointer;
transition: all 0.2s ease;
}
.delete-btn:hover {
background: #b71c1c !important;
transform: translateY(-1px);
}
/* 響應式設計 */
@media (max-width: 768px) {
.admin-container {
padding: 1.5rem;
}
form {
padding: 1.5rem;
}
.paper-table {
display: block;
overflow-x: auto;
}
th, td {
min-width: 200px;
}
}
.alert-container {
position: fixed;
top: 80px; /* 在導航欄下方 */
right: 20px;
z-index: 1000;
}
</style>
</head>
<body>
<!-- 提示信息容器 -->
<div class="alert-container">
<div th:if="${success}" class="alert success" th:text="${success}"></div>
<div th:if="${error}" class="alert error" th:text="${error}"></div>
</div>
<div class="admin-container">
<h2>試卷管理系統</h2>
<h3>新增試卷</h3>
<form th:action="@{/admin/papers}" method="post">
<input type="text" name="name" placeholder="試卷名稱" required>
<textarea name="content" placeholder="試卷內容" rows="4"></textarea>
<input type="text" name="answer" placeholder="答案">
<button type="submit">發布試卷</button>
</form>
<h3>試卷列表</h3>
<table class="paper-table">
<thead>
<tr>
<th style="width: 20%">試卷名稱</th>
<th style="width: 60%">試卷內容</th>
<th style="width: 20%">操作</th>
</tr>
</thead>
<tbody>
<tr th:each="paper : ${papers}">
<td th:text="${paper.name}"></td>
<td class="content-cell">
<div th:text="${paper.content}"></div>
</td>
<td>
<form class="delete-form"
th:action="@{/admin/papers/delete/{id}(id=${paper.id})}"
method="post"
onsubmit="return confirm('確定刪除該試卷嗎?');">
<button type="submit" class="delete-btn">刪除</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
<script>
/* 自動隱藏提示 */
document.addEventListener('DOMContentLoaded', function() {
const alerts = document.querySelectorAll('.alert');
alerts.forEach(alert => {
setTimeout(() => {
alert.style.opacity = '0';
setTimeout(() => alert.remove(), 1000);
}, 3000);
});
});
</script>
</body>
</html>

浙公網安備 33010602011771號