From caa63444eb1592ec047f88014f6fcfa85a2fa23f Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Fri, 16 Jun 2023 13:34:21 +0800 Subject: [PATCH] up Signed-off-by: Chenx221 --- .../WEB-INF/views/teachermanage.jsp | 208 ++++++++--------- .../controller/TeacherController.java | 50 ++++ .../web/WEB-INF/views/teacherQueryResult.jsp | 216 ++++++++++++++++++ project2/web/WEB-INF/views/teachermanage.jsp | 208 ++++++++--------- 4 files changed, 466 insertions(+), 216 deletions(-) create mode 100644 project2/web/WEB-INF/views/teacherQueryResult.jsp diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp index b9de02b..362c4f1 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp @@ -162,10 +162,10 @@
@@ -544,112 +544,104 @@ }); - // function resetPWD(id) { - // $('#typeText5').val(id); - // $('#ex1-tab-2').tab('show'); - // } - // - // // 监听权限组选择框的变化 - // document.getElementById('role-select').addEventListener('change', function () { - // var roleSelect = document.getElementById('role-select'); - // var typeText4 = document.getElementById('typeText4'); - // - // // 如果选择的是管理员权限组,则禁用身份ID输入框;否则启用身份ID输入框 - // typeText4.disabled = roleSelect.value === 'admin'; - // }); - // - // //实现按钮的点击事件(禁用/启用用户) - // $(document).ready(function () { - // $('.btn-danger').on('click', function () { - // var id = $(this).closest('tr').find('td:first').text(); - // userdisabled(id); - // // console.log(id) // debug - // }); - // }); - // $(document).ready(function () { - // $('.btn-success').on('click', function () { - // var id = $(this).closest('tr').find('td:first').text(); - // userenabled(id); - // // console.log(id) // debug - // }); - // }); - // - // //使用ajax在后台发送post禁用/启用用户请求 - // function userdisabled(id) { - // //btn-danger - // $.ajax({ - // url: 'userdisabled', - // type: 'post', - // data: { - // id: id - // }, - // success: function (data) { - // if (data.status === 'success') { - // $('#de_message').text(data.message); - // $('#de_button').on('click', function () { - // reloadka("reload"); - // }); - // $('#exampleModal3').modal('show'); - // $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 - // reloadka("reload"); - // }); - // } else { - // $('#de_message').text(data.message); - // $('#de_button').on('click', function () { - // reloadka("close"); - // }); - // $('#exampleModal3').modal('show'); - // } - // }, - // error: function (xhr, status, error) { - // // 处理请求失败的逻辑 - // console.log('请求失败:', error); - // alert('请求请求失败,请重试'); - // } - // }); - // } - // - // function userenabled(id) { - // $.ajax({ - // url: 'userenabled', - // type: 'post', - // data: { - // id: id - // }, - // success: function (data) { - // if (data.status === 'success') { - // $('#de_message').text(data.message); - // $('#de_button').on('click', function () { - // reloadka("reload"); - // }); - // $('#exampleModal3').modal('show'); - // $('#exampleModal3').on('hidden.bs.modal', function () { - // reloadka("reload"); - // }); - // } else { - // $('#de_message').text(data.message); - // $('#de_button').on('click', function () { - // reloadka("close"); - // }); - // $('#exampleModal3').modal('show'); - // } - // }, - // error: function (xhr, status, error) { - // // 处理请求失败的逻辑 - // console.log('请求失败:', error); - // alert('请求请求失败,请重试'); - // } - // }); - // } - // - // //处理成功/失败后的刷新页面/关闭模态框操作 - // function reloadka(action) { - // if (action === 'reload') { - // window.location.reload(); - // } else if (action === 'close') { - // $('#exampleModal3').modal('hide'); - // } - // } + function resetPWD(id) { + $('#typeText5').val(id); + $('#ex1-tab-2').tab('show'); + } + + + //实现按钮的点击事件(禁用/启用用户) + $(document).ready(function () { + $('.btn-danger').on('click', function () { + var id = $(this).closest('tr').find('td:first').text(); + userdisabled(id); + // console.log(id) // debug + }); + }); + $(document).ready(function () { + $('.btn-success').on('click', function () { + var id = $(this).closest('tr').find('td:first').text(); + userenabled(id); + // console.log(id) // debug + }); + }); + + //使用ajax在后台发送post禁用/启用用户请求 + function userdisabled(id) { + //btn-danger + $.ajax({ + url: 'userdisabled', + type: 'post', + data: { + id: id + }, + success: function (data) { + if (data.status === 'success') { + $('#de_message').text(data.message); + $('#de_button').on('click', function () { + reloadka("reload"); + }); + $('#exampleModal3').modal('show'); + $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 + reloadka("reload"); + }); + } else { + $('#de_message').text(data.message); + $('#de_button').on('click', function () { + reloadka("close"); + }); + $('#exampleModal3').modal('show'); + } + }, + error: function (xhr, status, error) { + // 处理请求失败的逻辑 + console.log('请求失败:', error); + alert('请求请求失败,请重试'); + } + }); + } + + function userenabled(id) { + $.ajax({ + url: 'userenabled', + type: 'post', + data: { + id: id + }, + success: function (data) { + if (data.status === 'success') { + $('#de_message').text(data.message); + $('#de_button').on('click', function () { + reloadka("reload"); + }); + $('#exampleModal3').modal('show'); + $('#exampleModal3').on('hidden.bs.modal', function () { + reloadka("reload"); + }); + } else { + $('#de_message').text(data.message); + $('#de_button').on('click', function () { + reloadka("close"); + }); + $('#exampleModal3').modal('show'); + } + }, + error: function (xhr, status, error) { + // 处理请求失败的逻辑 + console.log('请求失败:', error); + alert('请求请求失败,请重试'); + } + }); + } + + //处理成功/失败后的刷新页面/关闭模态框操作 + function reloadka(action) { + if (action === 'reload') { + window.location.reload(); + } else if (action === 'close') { + $('#exampleModal3').modal('hide'); + } + } diff --git a/project2/src/main/java/cyou/chenx221/controller/TeacherController.java b/project2/src/main/java/cyou/chenx221/controller/TeacherController.java index 0964f00..278a711 100644 --- a/project2/src/main/java/cyou/chenx221/controller/TeacherController.java +++ b/project2/src/main/java/cyou/chenx221/controller/TeacherController.java @@ -1,14 +1,21 @@ package cyou.chenx221.controller; +import cyou.chenx221.helper.CsvHelper; 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.service.TeacherService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; 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.RequestParam; +import java.io.IOException; import java.util.List; @Controller @@ -31,4 +38,47 @@ public class TeacherController { model.addAttribute("teacherList", teacherList); 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 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"; + } } diff --git a/project2/web/WEB-INF/views/teacherQueryResult.jsp b/project2/web/WEB-INF/views/teacherQueryResult.jsp new file mode 100644 index 0000000..a6028ba --- /dev/null +++ b/project2/web/WEB-INF/views/teacherQueryResult.jsp @@ -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" %> + + + + + + + + 教师信息查询结果页 + + + + + + + + + + +
+ +
+ + + + +
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
教师ID姓名性别出生日期授课课程ID授课课程名授课班级
${teacher.id}${teacher.name}${teacher.sex}${teacher.birthday}${teacher.course.courseID}${teacher.course.courseName}${teacher.classes}
+
+
+
+
+
+ + + + +
+
+ + + + + + + + + \ No newline at end of file diff --git a/project2/web/WEB-INF/views/teachermanage.jsp b/project2/web/WEB-INF/views/teachermanage.jsp index b9de02b..362c4f1 100644 --- a/project2/web/WEB-INF/views/teachermanage.jsp +++ b/project2/web/WEB-INF/views/teachermanage.jsp @@ -162,10 +162,10 @@
@@ -544,112 +544,104 @@ }); - // function resetPWD(id) { - // $('#typeText5').val(id); - // $('#ex1-tab-2').tab('show'); - // } - // - // // 监听权限组选择框的变化 - // document.getElementById('role-select').addEventListener('change', function () { - // var roleSelect = document.getElementById('role-select'); - // var typeText4 = document.getElementById('typeText4'); - // - // // 如果选择的是管理员权限组,则禁用身份ID输入框;否则启用身份ID输入框 - // typeText4.disabled = roleSelect.value === 'admin'; - // }); - // - // //实现按钮的点击事件(禁用/启用用户) - // $(document).ready(function () { - // $('.btn-danger').on('click', function () { - // var id = $(this).closest('tr').find('td:first').text(); - // userdisabled(id); - // // console.log(id) // debug - // }); - // }); - // $(document).ready(function () { - // $('.btn-success').on('click', function () { - // var id = $(this).closest('tr').find('td:first').text(); - // userenabled(id); - // // console.log(id) // debug - // }); - // }); - // - // //使用ajax在后台发送post禁用/启用用户请求 - // function userdisabled(id) { - // //btn-danger - // $.ajax({ - // url: 'userdisabled', - // type: 'post', - // data: { - // id: id - // }, - // success: function (data) { - // if (data.status === 'success') { - // $('#de_message').text(data.message); - // $('#de_button').on('click', function () { - // reloadka("reload"); - // }); - // $('#exampleModal3').modal('show'); - // $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 - // reloadka("reload"); - // }); - // } else { - // $('#de_message').text(data.message); - // $('#de_button').on('click', function () { - // reloadka("close"); - // }); - // $('#exampleModal3').modal('show'); - // } - // }, - // error: function (xhr, status, error) { - // // 处理请求失败的逻辑 - // console.log('请求失败:', error); - // alert('请求请求失败,请重试'); - // } - // }); - // } - // - // function userenabled(id) { - // $.ajax({ - // url: 'userenabled', - // type: 'post', - // data: { - // id: id - // }, - // success: function (data) { - // if (data.status === 'success') { - // $('#de_message').text(data.message); - // $('#de_button').on('click', function () { - // reloadka("reload"); - // }); - // $('#exampleModal3').modal('show'); - // $('#exampleModal3').on('hidden.bs.modal', function () { - // reloadka("reload"); - // }); - // } else { - // $('#de_message').text(data.message); - // $('#de_button').on('click', function () { - // reloadka("close"); - // }); - // $('#exampleModal3').modal('show'); - // } - // }, - // error: function (xhr, status, error) { - // // 处理请求失败的逻辑 - // console.log('请求失败:', error); - // alert('请求请求失败,请重试'); - // } - // }); - // } - // - // //处理成功/失败后的刷新页面/关闭模态框操作 - // function reloadka(action) { - // if (action === 'reload') { - // window.location.reload(); - // } else if (action === 'close') { - // $('#exampleModal3').modal('hide'); - // } - // } + function resetPWD(id) { + $('#typeText5').val(id); + $('#ex1-tab-2').tab('show'); + } + + + //实现按钮的点击事件(禁用/启用用户) + $(document).ready(function () { + $('.btn-danger').on('click', function () { + var id = $(this).closest('tr').find('td:first').text(); + userdisabled(id); + // console.log(id) // debug + }); + }); + $(document).ready(function () { + $('.btn-success').on('click', function () { + var id = $(this).closest('tr').find('td:first').text(); + userenabled(id); + // console.log(id) // debug + }); + }); + + //使用ajax在后台发送post禁用/启用用户请求 + function userdisabled(id) { + //btn-danger + $.ajax({ + url: 'userdisabled', + type: 'post', + data: { + id: id + }, + success: function (data) { + if (data.status === 'success') { + $('#de_message').text(data.message); + $('#de_button').on('click', function () { + reloadka("reload"); + }); + $('#exampleModal3').modal('show'); + $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 + reloadka("reload"); + }); + } else { + $('#de_message').text(data.message); + $('#de_button').on('click', function () { + reloadka("close"); + }); + $('#exampleModal3').modal('show'); + } + }, + error: function (xhr, status, error) { + // 处理请求失败的逻辑 + console.log('请求失败:', error); + alert('请求请求失败,请重试'); + } + }); + } + + function userenabled(id) { + $.ajax({ + url: 'userenabled', + type: 'post', + data: { + id: id + }, + success: function (data) { + if (data.status === 'success') { + $('#de_message').text(data.message); + $('#de_button').on('click', function () { + reloadka("reload"); + }); + $('#exampleModal3').modal('show'); + $('#exampleModal3').on('hidden.bs.modal', function () { + reloadka("reload"); + }); + } else { + $('#de_message').text(data.message); + $('#de_button').on('click', function () { + reloadka("close"); + }); + $('#exampleModal3').modal('show'); + } + }, + error: function (xhr, status, error) { + // 处理请求失败的逻辑 + console.log('请求失败:', error); + alert('请求请求失败,请重试'); + } + }); + } + + //处理成功/失败后的刷新页面/关闭模态框操作 + function reloadka(action) { + if (action === 'reload') { + window.location.reload(); + } else if (action === 'close') { + $('#exampleModal3').modal('hide'); + } + }