Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
Chenx221 2023-06-16 13:34:21 +08:00
parent 317172aa4b
commit caa63444eb
4 changed files with 466 additions and 216 deletions

View File

@ -162,10 +162,10 @@
<td class="text-center"> <td class="text-center">
<div class="btn-group" role="group" aria-label="Basic example"> <div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-danger"> <button type="button" class="btn btn-danger">
<i class="fas fa-pencil me-1"></i>禁用账户 <i class="fas fa-pencil"></i>
</button> </button>
<button type="button" class="btn btn-primary"> <button type="button" class="btn btn-primary">
<i class="fas fa-trash me-1"></i>重设密码 <i class="fas fa-trash"></i>
</button> </button>
</div> </div>
</td> </td>
@ -544,112 +544,104 @@
</c:if> </c:if>
}); });
// function resetPWD(id) { function resetPWD(id) {
// $('#typeText5').val(id); $('#typeText5').val(id);
// $('#ex1-tab-2').tab('show'); $('#ex1-tab-2').tab('show');
// } }
//
// // 监听权限组选择框的变化
// document.getElementById('role-select').addEventListener('change', function () { //实现按钮的点击事件(禁用/启用用户)
// var roleSelect = document.getElementById('role-select'); $(document).ready(function () {
// var typeText4 = document.getElementById('typeText4'); $('.btn-danger').on('click', function () {
// var id = $(this).closest('tr').find('td:first').text();
// // 如果选择的是管理员权限组则禁用身份ID输入框否则启用身份ID输入框 userdisabled(id);
// typeText4.disabled = roleSelect.value === 'admin'; // console.log(id) // debug
// }); });
// });
// //实现按钮的点击事件(禁用/启用用户) $(document).ready(function () {
// $(document).ready(function () { $('.btn-success').on('click', function () {
// $('.btn-danger').on('click', function () { var id = $(this).closest('tr').find('td:first').text();
// var id = $(this).closest('tr').find('td:first').text(); userenabled(id);
// userdisabled(id); // console.log(id) // debug
// // console.log(id) // debug });
// }); });
// });
// $(document).ready(function () { //使用ajax在后台发送post禁用/启用用户请求
// $('.btn-success').on('click', function () { function userdisabled(id) {
// var id = $(this).closest('tr').find('td:first').text(); //btn-danger
// userenabled(id); $.ajax({
// // console.log(id) // debug url: 'userdisabled',
// }); type: 'post',
// }); data: {
// id: id
// //使用ajax在后台发送post禁用/启用用户请求 },
// function userdisabled(id) { success: function (data) {
// //btn-danger if (data.status === 'success') {
// $.ajax({ $('#de_message').text(data.message);
// url: 'userdisabled', $('#de_button').on('click', function () {
// type: 'post', reloadka("reload");
// data: { });
// id: id $('#exampleModal3').modal('show');
// }, $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理
// success: function (data) { reloadka("reload");
// if (data.status === 'success') { });
// $('#de_message').text(data.message); } else {
// $('#de_button').on('click', function () { $('#de_message').text(data.message);
// reloadka("reload"); $('#de_button').on('click', function () {
// }); reloadka("close");
// $('#exampleModal3').modal('show'); });
// $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 $('#exampleModal3').modal('show');
// reloadka("reload"); }
// }); },
// } else { error: function (xhr, status, error) {
// $('#de_message').text(data.message); // 处理请求失败的逻辑
// $('#de_button').on('click', function () { console.log('请求失败:', error);
// reloadka("close"); alert('请求请求失败,请重试');
// }); }
// $('#exampleModal3').modal('show'); });
// } }
// },
// error: function (xhr, status, error) { function userenabled(id) {
// // 处理请求失败的逻辑 $.ajax({
// console.log('请求失败:', error); url: 'userenabled',
// alert('请求请求失败,请重试'); type: 'post',
// } data: {
// }); id: id
// } },
// success: function (data) {
// function userenabled(id) { if (data.status === 'success') {
// $.ajax({ $('#de_message').text(data.message);
// url: 'userenabled', $('#de_button').on('click', function () {
// type: 'post', reloadka("reload");
// data: { });
// id: id $('#exampleModal3').modal('show');
// }, $('#exampleModal3').on('hidden.bs.modal', function () {
// success: function (data) { reloadka("reload");
// if (data.status === 'success') { });
// $('#de_message').text(data.message); } else {
// $('#de_button').on('click', function () { $('#de_message').text(data.message);
// reloadka("reload"); $('#de_button').on('click', function () {
// }); reloadka("close");
// $('#exampleModal3').modal('show'); });
// $('#exampleModal3').on('hidden.bs.modal', function () { $('#exampleModal3').modal('show');
// reloadka("reload"); }
// }); },
// } else { error: function (xhr, status, error) {
// $('#de_message').text(data.message); // 处理请求失败的逻辑
// $('#de_button').on('click', function () { console.log('请求失败:', error);
// reloadka("close"); alert('请求请求失败,请重试');
// }); }
// $('#exampleModal3').modal('show'); });
// } }
// },
// error: function (xhr, status, error) { //处理成功/失败后的刷新页面/关闭模态框操作
// // 处理请求失败的逻辑 function reloadka(action) {
// console.log('请求失败:', error); if (action === 'reload') {
// alert('请求请求失败,请重试'); window.location.reload();
// } } else if (action === 'close') {
// }); $('#exampleModal3').modal('hide');
// } }
// }
// //处理成功/失败后的刷新页面/关闭模态框操作
// function reloadka(action) {
// if (action === 'reload') {
// window.location.reload();
// } else if (action === 'close') {
// $('#exampleModal3').modal('hide');
// }
// }
</script> </script>
</body> </body>

View File

@ -1,14 +1,21 @@
package cyou.chenx221.controller; package cyou.chenx221.controller;
import cyou.chenx221.helper.CsvHelper;
import cyou.chenx221.helper.UsernameHelper; import cyou.chenx221.helper.UsernameHelper;
import cyou.chenx221.pojo.Course;
import cyou.chenx221.pojo.Score;
import cyou.chenx221.pojo.Student;
import cyou.chenx221.pojo.Teacher; import cyou.chenx221.pojo.Teacher;
import cyou.chenx221.service.TeacherService; import cyou.chenx221.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.io.IOException;
import java.util.List; import java.util.List;
@Controller @Controller
@ -31,4 +38,47 @@ public class TeacherController {
model.addAttribute("teacherList", teacherList); model.addAttribute("teacherList", teacherList);
return "teachermanage"; return "teachermanage";
} }
@PostMapping(value = "/query", produces = "application/x-www-form-urlencoded;charset=UTF-8")
public String postQuery(@RequestParam(value = "id", defaultValue = "-1", required = false) int id,//教师id
@RequestParam(value = "name", defaultValue = "null", required = false) String name,//学生姓名
@RequestParam(value = "coursename", defaultValue = "null", required = false) String course_name,//课程名
@RequestParam(value = "scoreid", defaultValue = "-1", required = false) int score_id,//成绩ID
@RequestParam(value = "studentid", defaultValue = "-1", required = false) int student_id,//学号
@RequestParam(value = "courseid", defaultValue = "-1", required = false) int course_id,//课程ID
@RequestParam(value = "min", defaultValue = "-1", required = false) int min,//最低分
@RequestParam(value = "max", defaultValue = "-1", required = false) int max,//最高分
@RequestParam(value = "range_enabler", defaultValue = "false", required = false) boolean range_enabler,//是否启用分数范围
Model model) throws IOException {
//username helper start
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
//username helper end
if (name.equals("null")) {
name = null;
}
if (course_name.equals("null")) {
course_name = null;
}
// System.out.println("name: " + name + " course_name: " + course_name + " score_id: " + score_id + " student_id: " + student_id + " course_id: " + course_id + " min: " + min + " max: " + max + " range_enabler: " + range_enabler);
if (score_id == -1 && student_id == -1 && course_id == -1 && !range_enabler && course_name == null && name == null) {
model.addAttribute("errorMessage", "查询条件不可全为空");
return "redirect:/score/infomodv2";
}
List<Score> scores;
Score score;
score = new Score((score_id == -1 ? null : score_id), ((student_id == -1 && name == null) ? null : (new Student((student_id == -1 ? null : student_id), name))), (course_id == -1 && course_name == null) ? null : (new Course((course_id == -1 ? null : course_id), course_name)), range_enabler ? (min == -1 ? null : min) : null, range_enabler ? (max == -1 ? null : max) : null);
scores = scoreService.getQueryScores(score);
String download = new CsvHelper().generateScoreCSVFile(scores);
model.addAttribute("download", download);
model.addAttribute("scores", scores);
return "scoreQueryResult";
}
} }

View File

@ -0,0 +1,216 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<meta http-equiv="x-ua-compatible" content="ie=edge"/>
<title>教师信息查询结果页</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/mdb.min.css"/>
<style>
.table-container {
min-width: 80vw; /* 设置最小宽度为视窗宽度的80% */
min-height: 80vh; /* 设置最小高度为视窗高度的80% */
/*display: flex;*/
align-items: center;
justify-content: center;
}
.table-container table {
width: 100%;
height: 100%;
}
</style>
</head>
<body style="font-family: 'Noto Sans SC Regular',serif">
<!--Main Navigation-->
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light" style="z-index: 1;min-height: 58.59px">
<div class="container">
<button class="navbar-toggler" type="button" data-mdb-toggle="collapse"
data-mdb-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<a class="navbar-brand mt-2 mt-lg-0" href="#">
<i class="fas fa-chalkboard-user me-2"></i>
教务管理系统
</a>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">首页</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown1" role="button"
data-mdb-toggle="dropdown" aria-expanded="false">
学生管理
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown1">
<li><a class="dropdown-item" href="#">学生信息查询</a></li>
<li><a class="dropdown-item" href="#">学生信息管理</a></li>
<li><a class="dropdown-item" href="#">学生信息管理</a></li>
<li>
<hr class="dropdown-divider"/>
</li>
<li><a class="dropdown-item" href="#">学生成绩管理</a></li>
<li><a class="dropdown-item" href="#">学生成绩管理</a></li>
<li><a class="dropdown-item" href="#">学生成绩管理</a></li>
<li>
<hr class="dropdown-divider"/>
</li>
<li><a class="dropdown-item" href="#">学生选课管理</a></li>
<li><a class="dropdown-item" href="#">学生选课管理</a></li>
<li><a class="dropdown-item" href="#">学生选课管理</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown2" role="button"
data-mdb-toggle="dropdown" aria-expanded="false">
教师管理
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown2">
<li><a class="dropdown-item" href="#">教师信息管理</a></li>
<li><a class="dropdown-item" href="#">教师课程管理</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown3" role="button"
data-mdb-toggle="dropdown" aria-expanded="false">
课程管理
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown3">
<li><a class="dropdown-item" href="#">课程信息管理</a></li>
<li><a class="dropdown-item" href="#">课程安排管理</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown4" role="button"
data-mdb-toggle="dropdown" aria-expanded="false">
系统管理
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown4">
<li><a class="dropdown-item" href="#">个人设定</a></li>
<li><a class="dropdown-item" href="#">用户管理</a></li>
<li><a class="dropdown-item" href="#">日志管理</a></li>
<li><a class="dropdown-item" href="#">版本信息</a></li>
</ul>
</li>
</ul>
</div>
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>
<a class="dropdown-item" href="${pageContext.request.contextPath}/logout">登出</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!--Main Navigation-->
<!--Main layout-->
<main>
<div class="bg-image shadow-2-strong vh-100"
style="background-image: url('${pageContext.request.contextPath}/resources/img/jason-blackeye-nyL-rzwP-Mk-unsplash.jpg'); margin-top: -58.59px;">
<div class="mask d-flex align-items-center h-100" style="background-color: hsla(0, 0%, 100%, 0.5);">
<div class="container d-flex justify-content-center">
<div>
<div class="row">
<div class="col-12">
<button type="button" class="btn btn-primary" onclick="location.href='../dashboard'">返回
</button>
</div>
</div>
<div class="row">
<div class="col-12">
<button type="button" class="btn btn-primary" onclick="downloadCSV()">导出</button>
</div>
</div>
</div>
<div class="table-container rounded-4 shadow-3-strong"
style="background-color: rgba(255,255,255,0.9); overflow-y: auto; max-height: 400px;">
<table class="table table-striped table-hover border-primary">
<thead>
<tr>
<th scope="col">教师ID</th>
<th scope="col">姓名</th>
<th scope="col">性别</th>
<th scope="col">出生日期</th>
<th scope="col">授课课程ID</th>
<th scope="col">授课课程名</th>
<th scope="col">授课班级</th>
</tr>
</thead>
<tbody>
<c:forEach var="teacher" items="${teacherList}">
<tr>
<td>${teacher.id}</td>
<td>${teacher.name}</td>
<td>${teacher.sex}</td>
<td>${teacher.birthday}</td>
<td>${teacher.course.courseID}</td>
<td>${teacher.course.courseName}</td>
<td>${teacher.classes}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
</div>
</main>
<!--Main layout-->
<!-- Footer -->
<footer class="bg-link text-center text-lg-start ">
</footer>
<!-- Footer -->
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/mdb.min.js"></script>
<script>
function downloadCSV() {
// 获取文件名
var fileName = "${download}";
// 构建文件下载链接
var downloadLink = "/output/get-csv?filename=" + fileName;
// 创建一个隐藏的<a>元素并设置下载链接
var linkElement = document.createElement('a');
linkElement.href = downloadLink;
linkElement.target = "_blank";
linkElement.download = fileName;
// 将<a>元素添加到DOM树中
document.body.appendChild(linkElement);
// 模拟点击<a>元素来触发下载操作
linkElement.click();
// 从DOM树中移除<a>元素
document.body.removeChild(linkElement);
}
</script>
</body>
</html>

View File

@ -162,10 +162,10 @@
<td class="text-center"> <td class="text-center">
<div class="btn-group" role="group" aria-label="Basic example"> <div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-danger"> <button type="button" class="btn btn-danger">
<i class="fas fa-pencil me-1"></i>禁用账户 <i class="fas fa-pencil"></i>
</button> </button>
<button type="button" class="btn btn-primary"> <button type="button" class="btn btn-primary">
<i class="fas fa-trash me-1"></i>重设密码 <i class="fas fa-trash"></i>
</button> </button>
</div> </div>
</td> </td>
@ -544,112 +544,104 @@
</c:if> </c:if>
}); });
// function resetPWD(id) { function resetPWD(id) {
// $('#typeText5').val(id); $('#typeText5').val(id);
// $('#ex1-tab-2').tab('show'); $('#ex1-tab-2').tab('show');
// } }
//
// // 监听权限组选择框的变化
// document.getElementById('role-select').addEventListener('change', function () { //实现按钮的点击事件(禁用/启用用户)
// var roleSelect = document.getElementById('role-select'); $(document).ready(function () {
// var typeText4 = document.getElementById('typeText4'); $('.btn-danger').on('click', function () {
// var id = $(this).closest('tr').find('td:first').text();
// // 如果选择的是管理员权限组则禁用身份ID输入框否则启用身份ID输入框 userdisabled(id);
// typeText4.disabled = roleSelect.value === 'admin'; // console.log(id) // debug
// }); });
// });
// //实现按钮的点击事件(禁用/启用用户) $(document).ready(function () {
// $(document).ready(function () { $('.btn-success').on('click', function () {
// $('.btn-danger').on('click', function () { var id = $(this).closest('tr').find('td:first').text();
// var id = $(this).closest('tr').find('td:first').text(); userenabled(id);
// userdisabled(id); // console.log(id) // debug
// // console.log(id) // debug });
// }); });
// });
// $(document).ready(function () { //使用ajax在后台发送post禁用/启用用户请求
// $('.btn-success').on('click', function () { function userdisabled(id) {
// var id = $(this).closest('tr').find('td:first').text(); //btn-danger
// userenabled(id); $.ajax({
// // console.log(id) // debug url: 'userdisabled',
// }); type: 'post',
// }); data: {
// id: id
// //使用ajax在后台发送post禁用/启用用户请求 },
// function userdisabled(id) { success: function (data) {
// //btn-danger if (data.status === 'success') {
// $.ajax({ $('#de_message').text(data.message);
// url: 'userdisabled', $('#de_button').on('click', function () {
// type: 'post', reloadka("reload");
// data: { });
// id: id $('#exampleModal3').modal('show');
// }, $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理
// success: function (data) { reloadka("reload");
// if (data.status === 'success') { });
// $('#de_message').text(data.message); } else {
// $('#de_button').on('click', function () { $('#de_message').text(data.message);
// reloadka("reload"); $('#de_button').on('click', function () {
// }); reloadka("close");
// $('#exampleModal3').modal('show'); });
// $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 $('#exampleModal3').modal('show');
// reloadka("reload"); }
// }); },
// } else { error: function (xhr, status, error) {
// $('#de_message').text(data.message); // 处理请求失败的逻辑
// $('#de_button').on('click', function () { console.log('请求失败:', error);
// reloadka("close"); alert('请求请求失败,请重试');
// }); }
// $('#exampleModal3').modal('show'); });
// } }
// },
// error: function (xhr, status, error) { function userenabled(id) {
// // 处理请求失败的逻辑 $.ajax({
// console.log('请求失败:', error); url: 'userenabled',
// alert('请求请求失败,请重试'); type: 'post',
// } data: {
// }); id: id
// } },
// success: function (data) {
// function userenabled(id) { if (data.status === 'success') {
// $.ajax({ $('#de_message').text(data.message);
// url: 'userenabled', $('#de_button').on('click', function () {
// type: 'post', reloadka("reload");
// data: { });
// id: id $('#exampleModal3').modal('show');
// }, $('#exampleModal3').on('hidden.bs.modal', function () {
// success: function (data) { reloadka("reload");
// if (data.status === 'success') { });
// $('#de_message').text(data.message); } else {
// $('#de_button').on('click', function () { $('#de_message').text(data.message);
// reloadka("reload"); $('#de_button').on('click', function () {
// }); reloadka("close");
// $('#exampleModal3').modal('show'); });
// $('#exampleModal3').on('hidden.bs.modal', function () { $('#exampleModal3').modal('show');
// reloadka("reload"); }
// }); },
// } else { error: function (xhr, status, error) {
// $('#de_message').text(data.message); // 处理请求失败的逻辑
// $('#de_button').on('click', function () { console.log('请求失败:', error);
// reloadka("close"); alert('请求请求失败,请重试');
// }); }
// $('#exampleModal3').modal('show'); });
// } }
// },
// error: function (xhr, status, error) { //处理成功/失败后的刷新页面/关闭模态框操作
// // 处理请求失败的逻辑 function reloadka(action) {
// console.log('请求失败:', error); if (action === 'reload') {
// alert('请求请求失败,请重试'); window.location.reload();
// } } else if (action === 'close') {
// }); $('#exampleModal3').modal('hide');
// } }
// }
// //处理成功/失败后的刷新页面/关闭模态框操作
// function reloadka(action) {
// if (action === 'reload') {
// window.location.reload();
// } else if (action === 'close') {
// $('#exampleModal3').modal('hide');
// }
// }
</script> </script>
</body> </body>