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 e683420..dc7078d 100644
Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/TeacherController.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/TeacherController.class differ
diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teacherQueryResult.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teacherQueryResult.jsp
new file mode 100644
index 0000000..a6028ba
--- /dev/null
+++ b/project2/out/artifacts/project2_war_exploded/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/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 @@
-
+