fix part3

Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
Chenx221 2023-06-19 20:22:42 +08:00
parent 52ebf32766
commit bf3e198ed2
17 changed files with 330 additions and 106 deletions

View File

@ -70,40 +70,35 @@
- *Redirect*.infomodv2|*Redirect*.infomodv2_t
- /student
- ~/all
- 学生信息查询页
- admin
- ~/all_t
- 学生信息查询页(教师版)
- teacher
- 学生信息查询页 [Get]
- admin,teacher,student
- studentList|studentList_t|studentList_s
- ~/queryinfo
- 学生信息查询(条件)页
- admin
- ~/queryinfo_t
- 学生信息查询(条件)页(教师版)
- teacher
- 学生信息查询(条件)页 [Get]
- admin,teacher
- studentListQuery|studentListQuery_t
- ~/query
- 学生信息查询
- admin
- 学生信息查询 [Post]
- admin,teacher
- studentQueryResult|studentQueryResult_t
- ~/modstep1
- 学生信息修改页
- admin
- ~/modinfo
- 学生信息修改页(过时) [Get]
- admin,teacher
- studentMod|studentMod_t
- ~/modinfo [Post]
- 学生信息修改
- admin,teacher
- *Redirect*.infomodv2|*Redirect*.infomodv2_t
- ~/infomodv2
- 学生信息修改页(v2)
- admin
- ~/infomodv2_t
- 学生信息修改页(v2)(教师版)
- teacher
- 学生信息修改页(v2) [Get]
- admin,teacher
- studentinfomodv2|studentinfomodv2_t
- ~/delinfo
- 学生信息删除
- admin
- ~/delinfoT
- 学生信息删除(教师版)
- teacher
- 学生信息删除 [Post]
- admin,teacher
- *Redirect*.infomodv2|*Redirect*.infomodv2_t
- ~/addinfo
- 学生信息添加
- 学生信息添加 [Post]
- admin,teacher
- /system
- ~/settings

View File

@ -37,22 +37,23 @@ public class StudentController {
if (username != null) {
model.addAttribute("username", username);
}
List<Student> students = studentService.getAllStudents();
model.addAttribute("students", students);
return "studentList"; // 重定向到 dashboard 页面
}
@GetMapping("/all_t")//学生信息查询不带条件(排除removed的学生
public String getAllStudentsT(Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
String role = new UsernameHelper().getCurrentRole();
if (role.equals("[ROLE_admin]")) {
List<Student> students = studentService.getAllStudents();
model.addAttribute("students", students);
return "student/studentList";
} else if (role.equals("[ROLE_teacher]")) {
String classes = teacherService.getClassesById(userMapper.getDetailByUsername(username));
List<Student> students = studentService.getAllStudentsT(classes);
model.addAttribute("classes", classes);
model.addAttribute("students", students);
return "student/studentList_t";
} else {
int id = studentService.getIdByUsername(username);
Student student = studentService.getStudentById(id);
model.addAttribute("student", student);
return "student/studentList_s";
}
String classes = teacherService.getClassesById(userMapper.getDetailByUsername(username));
List<Student> students = studentService.getAllStudentsT(classes);
model.addAttribute("classes", classes);
model.addAttribute("students", students);
return "studentList_t";
}
@GetMapping("/queryinfo")//处理访问学生信息查询
@ -61,17 +62,13 @@ public class StudentController {
if (username != null) {
model.addAttribute("username", username);
}
return "studentListQuery";
}
@GetMapping("/queryinfo_t")//处理访问学生信息查询
public String getQueryInfoT(Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
String role = new UsernameHelper().getCurrentRole();
if (role.equals("[ROLE_admin]"))
return "student/studentListQuery";
else {
model.addAttribute("classes", teacherService.getClassesById(userMapper.getDetailByUsername(username)));
return "student/studentListQuery_t";
}
model.addAttribute("classes", teacherService.getClassesById(userMapper.getDetailByUsername(username)));
return "studentListQuery_t";
}
@PostMapping(value = "/query", produces = "application/x-www-form-urlencoded;charset=UTF-8")//学生信息查询带条件
@ -118,7 +115,12 @@ public class StudentController {
students = studentService.getQueryStudents2(student);
}
model.addAttribute("students", students);
return "studentQueryResult";
String role = new UsernameHelper().getCurrentRole();
if (role.equals("[ROLE_admin]"))
return "student/studentQueryResult";
else {
return "student/studentQueryResult_t";
}
}
@GetMapping("/modstep1")//处理学生信息修改页
@ -134,7 +136,13 @@ public class StudentController {
// 将消息添加到Model中
model.addAttribute("successMessage", successMessage);
model.addAttribute("errorMessage", errorMessage);
return "studentMod";
String role = new UsernameHelper().getCurrentRole();
if (role.equals("[ROLE_admin]"))
return "student/studentMod";
else {
model.addAttribute("classes", teacherService.getClassesById(userMapper.getDetailByUsername(username)));
return "student/studentMod_t";
}
}
@PostMapping(value = "/modinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")//处理学生信息修改请求
@ -144,7 +152,6 @@ public class StudentController {
@RequestParam(value = "id", defaultValue = "-1", required = false) int id,
@RequestParam(value = "phone", defaultValue = "null", required = false) String phone,
@RequestParam(value = "classes", defaultValue = "", required = false) String classes,
@RequestParam(value = "cla", defaultValue = "null", required = false) String cla,
Model model) {
Date birthday = null;
if (!"null".equals(birthdayStr)) {
@ -164,9 +171,10 @@ public class StudentController {
studentService.updateStudent(student);
model.addAttribute("successMessage", "学生信息修改成功");
}
if (cla.equals("null")) {
String role = new UsernameHelper().getCurrentRole();
if (role.equals("[ROLE_admin]"))
return "redirect:/student/infomodv2";
} else {
else {
return "redirect:/student/infomodv2_t";
}
}
@ -179,64 +187,49 @@ public class StudentController {
if (username != null) {
model.addAttribute("username", username);
}
List<Student> students = studentService.getAllStudents();//和前面显示全部学生一样页面需要学生信息的显示
model.addAttribute("students", students);
// 将消息添加到Model中
model.addAttribute("successMessage", successMessage);
model.addAttribute("errorMessage", errorMessage);
return "studentinfomodv2";
}
@GetMapping("/infomodv2_t")//处理学生信息修改页
public String getInfoModv2T(@RequestParam(value = "successMessage", required = false, defaultValue = "null") String successMessage,
@RequestParam(value = "errorMessage", required = false, defaultValue = "null") String errorMessage,
Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
String classes = teacherService.getClassesById(userMapper.getDetailByUsername(username));
List<Student> students = studentService.getAllStudentsT(classes);
model.addAttribute("classes", classes);
model.addAttribute("students", students);
// 将消息添加到Model中
model.addAttribute("successMessage", successMessage);
model.addAttribute("errorMessage", errorMessage);
return "studentinfomodv2_t";
String role = new UsernameHelper().getCurrentRole();
if (role.equals("[ROLE_admin]")) {
List<Student> students = studentService.getAllStudents();
model.addAttribute("students", students);
return "student/studentinfomodv2";
} else {
String classes = teacherService.getClassesById(userMapper.getDetailByUsername(username));
List<Student> students = studentService.getAllStudentsT(classes);
model.addAttribute("classes", classes);
model.addAttribute("students", students);
return "student/studentinfomodv2_t";
}
}
@PostMapping(value = "/delinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")
public String UpdateModInfo(@RequestParam(value = "id") int id,
@RequestParam(value = "cla", required = false, defaultValue = "null") String classes,
Model model) {
Student temp = studentService.getStudentById(id);
if (id <= 0 || temp == null) {
model.addAttribute("errorMessage", "学生信息删除失败,可能是ID非法或者学生已删除");
} else {
// Student student = new Student(id);
studentService.deleteStudent(id);
model.addAttribute("successMessage", "学生信息删除成功");
}
return "redirect:/student/infomodv2";
}
@PostMapping(value = "/delinfoT", produces = "application/x-www-form-urlencoded;charset=UTF-8")
public String UpdateModInfoT(@RequestParam(value = "id") int id,
@RequestParam(value = "cla") String classes,
Model model) {
Student temp = studentService.getStudentById(id);
if (id <= 0 || temp == null) {
model.addAttribute("errorMessage", "学生信息删除失败,可能是ID非法或者学生已删除");
} else {
if (temp.getClasses().equals(classes)) {
if (classes.equals("null")) {
studentService.deleteStudent(id);
model.addAttribute("successMessage", "学生信息删除成功");
} else {
model.addAttribute("errorMessage", "学生信息删除失败,这名学生不属于您的班级");
if (temp.getClasses().equals(classes)) {
studentService.deleteStudent(id);
model.addAttribute("successMessage", "学生信息删除成功");
} else {
model.addAttribute("errorMessage", "学生信息删除失败,这名学生不属于您的班级");
}
}
}
return "redirect:/student/infomodv2_t";
String role = new UsernameHelper().getCurrentRole();
if (role.equals("[ROLE_admin]"))
return "redirect:/student/infomodv2";
else {
return "redirect:/student/infomodv2_t";
}
}
@PostMapping(value = "/addinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")
@ -245,7 +238,6 @@ public class StudentController {
@RequestParam(value = "sex") String sex,
@RequestParam(value = "phone") String phone,
@RequestParam(value = "classes") String classes,
@RequestParam(value = "spec" ,defaultValue = "null", required = false) String spec,
Model model) {
Student student;
String classesPattern = "[1-5]班";// 使用正则表达式验证班级格式
@ -260,9 +252,10 @@ public class StudentController {
studentService.insertStudent(student);
model.addAttribute("successMessage", "学生信息添加成功");
}
if(spec.equals("null")){
String role = new UsernameHelper().getCurrentRole();
if (role.equals("[ROLE_admin]"))
return "redirect:/student/infomodv2";
}else {
else {
return "redirect:/student/infomodv2_t";
}
}

View File

@ -17,4 +17,8 @@ public interface StudentDao {
void updateStudent(Student student);
List<Student> getAllStudentsT(String classes);
int getIdByUsername(String username);
int getDetailByUsername(String username);
}

View File

@ -32,6 +32,16 @@ public class StudentDaoImpl implements StudentDao {
return sqlSession.selectList("getAllStudentsT", classes);
}
@Override
public int getIdByUsername(String username) {
return sqlSession.selectOne("getIdByUsername", username);
}
@Override
public int getDetailByUsername(String username) {
return sqlSession.selectOne("getDetailByUsername", username);
}
@Override
public void deleteStudent(int id) {
sqlSession.update("deleteStudent", id);

View File

@ -49,4 +49,12 @@ public class StudentService {
public List<Student> getAllStudentsT(String classes) {
return studentDao.getAllStudentsT(classes);
}
public int getIdByUsername(String username) {
return studentDao.getIdByUsername(username);
}
public int getDetailByUsername(String username) {
return studentDao.getDetailByUsername(username);
}
}

View File

@ -70,9 +70,22 @@
VALUES (#{name}, #{birthday}, #{sex}, #{phone}, #{classes})
</insert>
<select id="getAllStudentsT" parameterType="String" resultType="cyou.chenx221.pojo.Student">
SELECT *
FROM student
WHERE removed = 0 AND classes = #{classes}
</select>
<select id="getAllStudentsT" parameterType="String" resultType="cyou.chenx221.pojo.Student">
SELECT *
FROM student
WHERE removed = 0
AND classes = #{classes}
</select>
<select id="getIdByUsername" parameterType="String" resultType="int">
SELECT id
FROM user
WHERE username = #{username}
</select>
<select id="getDetailByUsername" parameterType="String" resultType="int">
select detail
from user
where username = #{username}
</select>
</mapper>

View File

@ -0,0 +1,201 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" 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-t'">返回
</button>
</div>
</div>
<div class="row">
<div class="col-12">
<button type="button" class="btn btn-primary" onclick="exportCSV('${classes}')">导出
</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">联系方式</th>
<th scope="col">班级</th>
</tr>
</thead>
<tbody>
<tr>
<td>${student.id}</td>
<td>${student.name}</td>
<td>${student.sex}</td>
<td>${student.birthday}</td>
<td>${student.phone}</td>
<td>${student.classes}</td>
</tr>
</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 exportCSV(classes) {
// 构造请求 URL根据需要导出的类型传递参数
var exportUrl = '/output/export-csv?type=student&classes=' + classes; // 示例:导出学生数据
var link = document.createElement('a');
link.href = exportUrl;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
</script>
</body>
</html>

View File

@ -206,7 +206,7 @@
<div class="col-12">
<div class="form-outline">
<input type="text" id="typeText6" class="form-control"
name="classes"/>
name="classes" value="${classes}"/>
<label class="form-label" for="typeText6">班级</label>
</div>
</div>