From 4a4871eccfd7016d820fb8f16fc9d7bcee3852a3 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Fri, 16 Jun 2023 14:47:23 +0800 Subject: [PATCH] up Signed-off-by: Chenx221 --- .../controller/TeacherController.class | Bin 1621 -> 4311 bytes .../WEB-INF/views/teacherQueryResult.jsp | 216 ++++++++++++++++++ .../WEB-INF/views/teachermanage.jsp | 6 +- .../controller/TeacherController.java | 68 ++++-- .../java/cyou/chenx221/mapper/TeacherDao.java | 2 + .../chenx221/mapper/impl/TeacherDaoImpl.java | 5 + .../main/java/cyou/chenx221/pojo/Teacher.java | 28 +++ .../cyou/chenx221/service/TeacherService.java | 4 + .../main/resources/mapper/TeacherMapper.xml | 31 +++ project2/web/WEB-INF/views/teachermanage.jsp | 6 +- 10 files changed, 340 insertions(+), 26 deletions(-) create mode 100644 project2/out/artifacts/project2_war_exploded/WEB-INF/views/teacherQueryResult.jsp diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/TeacherController.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/TeacherController.class index e6834207ce47260c6b04b62a84b191c23f01ff30..dc7078d2b4bbb53bb277f1aa3847e98a0416b155 100644 GIT binary patch literal 4311 zcmb7H`F9i775<*Lk;k$HViidUgeBhODQ=)t0vfY8nA*g_#uO-}Bk9>5Jemm!xTFo1|@)Zs~G*PTG^gNjT}@r~J@=r2j-t+waYcBnuP{wJgnj_uY5jz29Bl zn}7Z1!+!!ej6dmUL%W8KBs$S0u~bEN3B~z$Sr2HCESyE!e6dlf*VWB=E57Ef{`93C?@mZQ1pfjH+c!xg}`}B+XK3 zETEo3HK13=`|nl1h7-Y>ADFzK(!7pGuwBEWN$kK*f!)pCw+4y`)88@Mj)AJdP-L1@t!VzMk)-b~k5rR;Wf7Lb=Psb5_ zLBo?tjNvGe4JYd>1T;cDYn8bJ%i@%dJdP^>PSDH#Qv-7vo)XyFFl|~{b7G|^D}m)Y zI>s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YqVAIo(*HEsOzLuUf#jiNvYhr!~L&NgQA|}ims4)o;)q2ULchSDU}=D^z!{M zH+1^=7QV^Z9(sBM-@>;!XW&(Q2QM;fM)5MedXZLs#2vp!xm1`jV@Q00N0>4H#eSqT zBn0XDe|@l}#yX&ZFDrRq$59RAT{_>xRjO^KYcDZDqg4Aoeh{YI5Ah?;{iU0eFLT$5 zPY_=5@ngJtfzZ~O&no7~UCisPm_KdBywQsJoMPU+(ete&UsxllD)nbHxeY%L-Aa@C h1;?+^*vPfl@dn4NGyIa@cko+|bW*>=AMi(H{s&xYo^}8L delta 338 zcmXw#yG{Z@6o$W95n*>kLxcn|;>H98mGy%63t0F7#?oplf-w|oY<-Ard<|k};RBf1 zX)JsMU%?pv9bz$a{&V}znfVMqtpED^`~n+_^#iuDxDQ$P1evNa-^Z{Jfx&q< +<%@ 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/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp index 362c4f1..9f55f30 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 @@ -225,7 +225,7 @@
@@ -273,7 +273,7 @@ + for="typeText8">授课班级(1~5班)
@@ -297,7 +297,7 @@
- +
diff --git a/project2/src/main/java/cyou/chenx221/controller/TeacherController.java b/project2/src/main/java/cyou/chenx221/controller/TeacherController.java index 278a711..0d7878f 100644 --- a/project2/src/main/java/cyou/chenx221/controller/TeacherController.java +++ b/project2/src/main/java/cyou/chenx221/controller/TeacherController.java @@ -16,6 +16,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import java.io.IOException; +import java.sql.Date; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.List; @Controller @@ -41,15 +45,14 @@ public class TeacherController { @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 { + @RequestParam(value = "name", defaultValue = "null", required = false) String name,//教师姓名 + @RequestParam(value = "sex", defaultValue = "null", required = false) String sex,//性别 + @RequestParam(value = "birthday_begin", defaultValue = "null", required = false) String birthday_begin_str,//日期起始 + @RequestParam(value = "birthday_end", defaultValue = "null", required = false) String birthday_end_str,//日期结束 + @RequestParam(value = "course_id", defaultValue = "-1", required = false) int course_id,//课程ID + @RequestParam(value = "course_name", defaultValue = "null", required = false) String course_name,//课程名 + @RequestParam(value = "classes", defaultValue = "null", required = false) String classes,//授课班级 + Model model) { //username helper start String username = new UsernameHelper().getCurrentUsername(); @@ -58,27 +61,52 @@ public class TeacherController { } //username helper end + String pattern = "yyyy-MM-dd"; // 日期字符串的格式,与HTML的input type为date的格式相对应 + DateFormat dateFormat = new SimpleDateFormat(pattern); + Date birthdayBegin = null, birthdayEnd = null; + try { + if (!birthday_begin_str.equals("null")) { + java.util.Date parsedBeginDate = dateFormat.parse(birthday_begin_str); + birthdayBegin = new Date(parsedBeginDate.getTime()); + } + if (!birthday_end_str.equals("null")) { + java.util.Date parsedEndDate = dateFormat.parse(birthday_end_str); + birthdayEnd = new Date(parsedEndDate.getTime()); + } + } catch (ParseException e) { + e.printStackTrace(); + } if (name.equals("null")) { name = null; } + if (sex.equals("null")) { + sex = 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"; + if (classes.equals("null")) { + classes = null; } - List scores; - Score score; + String classesPattern = "[1-5]班";// 使用正则表达式验证班级格式 - 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); + if (id <= 0 && name == null && sex == null && birthdayBegin == null && birthdayEnd == null && course_id <= 0 && course_name == null && classes == null) { + model.addAttribute("errorMessage", "ID非法或查询条件全为空"); + return "redirect:/teacher/manage"; + } else if (birthdayBegin != null && birthdayEnd != null) { + if (birthdayBegin.compareTo(birthdayEnd) > 0) {//birthdayBegin > birthdayEnd + model.addAttribute("errorMessage", "日期范围异常"); + return "redirect:/teacher/manage"; + } + } + Teacher teacher = new Teacher(id, name, sex, (course_id == -1 && course_name == null ? null : (new Course(course_id, course_name))), classes, birthdayBegin, birthdayEnd); + List teachers = teacherService.getQueryTeachers(teacher); - scores = scoreService.getQueryScores(score); - String download = new CsvHelper().generateScoreCSVFile(scores); - model.addAttribute("download", download); - model.addAttribute("scores", scores); +// scores = scoreService.getQueryScores(score); +// String download = new CsvHelper().generateScoreCSVFile(scores); +// model.addAttribute("download", download); +// model.addAttribute("scores", scores); return "scoreQueryResult"; } } diff --git a/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java b/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java index e0dc850..9d008eb 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java +++ b/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java @@ -8,4 +8,6 @@ import java.util.List; @Repository public interface TeacherDao { List getAllTeachers(); + + List getQueryTeachers(Teacher teacher); } diff --git a/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java b/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java index 12f8a7b..5771866 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java +++ b/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java @@ -21,4 +21,9 @@ public class TeacherDaoImpl implements TeacherDao { public List getAllTeachers() { return sqlSession.selectList("getAllTeachers"); } + + @Override + public List getQueryTeachers(Teacher teacher) { + return sqlSession.selectList("getQueryTeachers",teacher); + } } diff --git a/project2/src/main/java/cyou/chenx221/pojo/Teacher.java b/project2/src/main/java/cyou/chenx221/pojo/Teacher.java index d3d85cc..f046d8b 100644 --- a/project2/src/main/java/cyou/chenx221/pojo/Teacher.java +++ b/project2/src/main/java/cyou/chenx221/pojo/Teacher.java @@ -12,6 +12,34 @@ public class Teacher { private Course course;//课程 private String classes;//班级(目前仅单个班级) private Integer removed;//移除标志 + private Date birthdayBegin; + private Date birthdayEnd; + + public Date getBirthdayBegin() { + return birthdayBegin; + } + + public void setBirthdayBegin(Date birthdayBegin) { + this.birthdayBegin = birthdayBegin; + } + + public Date getBirthdayEnd() { + return birthdayEnd; + } + + public void setBirthdayEnd(Date birthdayEnd) { + this.birthdayEnd = birthdayEnd; + } + + public Teacher(Integer id, String name, String sex, Course course, String classes, Date birthdayBegin, Date birthdayEnd) { + this.id = id; + this.name = name; + this.sex = sex; + this.course = course; + this.classes = classes; + this.birthdayBegin = birthdayBegin; + this.birthdayEnd = birthdayEnd; + } @Override public String toString() { diff --git a/project2/src/main/java/cyou/chenx221/service/TeacherService.java b/project2/src/main/java/cyou/chenx221/service/TeacherService.java index f8ecf42..9c8131d 100644 --- a/project2/src/main/java/cyou/chenx221/service/TeacherService.java +++ b/project2/src/main/java/cyou/chenx221/service/TeacherService.java @@ -17,4 +17,8 @@ public class TeacherService { public List getAllTeachers() { return teacherDao.getAllTeachers(); } + + public List getQueryTeachers(Teacher teacher) { + return teacherDao.getQueryTeachers(teacher); + } } diff --git a/project2/src/main/resources/mapper/TeacherMapper.xml b/project2/src/main/resources/mapper/TeacherMapper.xml index e18e331..bf384bc 100644 --- a/project2/src/main/resources/mapper/TeacherMapper.xml +++ b/project2/src/main/resources/mapper/TeacherMapper.xml @@ -14,10 +14,41 @@ + + + \ 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 362c4f1..9f55f30 100644 --- a/project2/web/WEB-INF/views/teachermanage.jsp +++ b/project2/web/WEB-INF/views/teachermanage.jsp @@ -225,7 +225,7 @@
@@ -273,7 +273,7 @@ + for="typeText8">授课班级(1~5班)
@@ -297,7 +297,7 @@
- +