diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/CourseController.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/CourseController.class index 4bcea9a..350b1ca 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/CourseController.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/CourseController.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/CourseDao.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/CourseDao.class index 8931819..63324dd 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/CourseDao.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/CourseDao.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/CourseDaoImpl.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/CourseDaoImpl.class index 7328373..b9adee5 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/CourseDaoImpl.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/CourseDaoImpl.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/CourseService.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/CourseService.class index 4e39398..708b2f5 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/CourseService.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/CourseService.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/CourseMapper.xml b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/CourseMapper.xml index 5990dce..4b2e953 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/CourseMapper.xml +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/CourseMapper.xml @@ -35,4 +35,19 @@ WHERE CourseID = #{courseID} + + + UPDATE course + SET removed = 1 + WHERE CourseID = #{id} + + + INSERT INTO course (CourseName, Description) + VALUES (#{courseName}, #{description}) + \ No newline at end of file diff --git a/project2/src/main/java/cyou/chenx221/controller/CourseController.java b/project2/src/main/java/cyou/chenx221/controller/CourseController.java index 7da1179..fe9b1fc 100644 --- a/project2/src/main/java/cyou/chenx221/controller/CourseController.java +++ b/project2/src/main/java/cyou/chenx221/controller/CourseController.java @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import java.sql.Date; import java.util.List; @Controller @@ -42,43 +41,39 @@ public class CourseController { return "courseopv2"; } -// @PostMapping(value = "/delinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") -// public String UpdateModInfo(@RequestParam(value = "id") int id, -// 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 = "/addinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") -// public String InsertStudentInfo(@RequestParam(value = "name") String name, -// @RequestParam(value = "birthday") Date birthday, -// @RequestParam(value = "sex") String sex, -// @RequestParam(value = "phone") String phone, -// @RequestParam(value = "classes") String classes, -// Model model) { -// Student student; -// String classesPattern = "[1-5]班";// 使用正则表达式验证班级格式 -// -// //格式合法性检查 -// if (!sex.equals("男") && !sex.equals("女")) { -// model.addAttribute("errorMessage", "性别格式不正确,仅允许'男'或'女'"); -// } else if (!classes.matches(classesPattern)) { -// model.addAttribute("errorMessage", "班级格式不正确,格式应为?班(?为1~5之间的数字)"); -// } else { -// student = new Student(name, sex, birthday, phone, classes); -// studentService.insertStudent(student); -// model.addAttribute("successMessage", "学生信息添加成功"); -// } -// return "redirect:/student/infomodv2"; -// } -// + @PostMapping(value = "/delinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") + public String UpdateModInfo(@RequestParam(value = "id") int id, + Model model) { + Course temp = courseService.getCourseById(id); + if (id <= 0 || temp == null) { + model.addAttribute("errorMessage", "学生信息删除失败,可能是ID非法或者学生已删除"); + } else { + int status_code = courseService.deleteCourse(id); + if (status_code == 1) { + model.addAttribute("successMessage", "学生信息删除成功"); + } else if (status_code == 0) { + model.addAttribute("errorMessage", "学生信息删除失败,可能是ID非法或者学生已删除"); + } else { + model.addAttribute("errorMessage", "学生信息删除异常"); + System.out.println("DEBUG:异常删除,多条记录被删除"); + } + } + return "redirect:/course/infomodv2"; + } + + // + @PostMapping(value = "/addinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") + public String InsertCourseInfo(@RequestParam(value = "name", defaultValue = "null", required = false) String name, + @RequestParam(value = "description", defaultValue = "null", required = false) String description, + Model model) { + Course course; + course = new Course(name, description); + courseService.insertCourse(course); + model.addAttribute("successMessage", "学生信息添加成功"); + return "redirect:/course/infomodv2"; + } + + // @PostMapping(value = "/modinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") public String UpdateModInfo(@RequestParam(value = "name", defaultValue = "null", required = false) String name, @RequestParam(value = "description", defaultValue = "null", required = false) String description, @@ -93,11 +88,11 @@ public class CourseController { } else { course = new Course(id, name, description); int status_code = courseService.updateCourse(course); - if(status_code==1){ + if (status_code == 1) { model.addAttribute("successMessage", "课程信息修改成功"); - }else if(status_code==0) { + } else if (status_code == 0) { model.addAttribute("errorMessage", "课程信息修改失败,可能是ID非法或者课程不存在"); - }else{ + } else { model.addAttribute("errorMessage", "课程信息修改异常"); System.out.println("DEBUG:课程信息修改异常,存在多条记录被修改的情况"); } diff --git a/project2/src/main/java/cyou/chenx221/mapper/CourseDao.java b/project2/src/main/java/cyou/chenx221/mapper/CourseDao.java index 81af62f..c11e43a 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/CourseDao.java +++ b/project2/src/main/java/cyou/chenx221/mapper/CourseDao.java @@ -12,4 +12,10 @@ public interface CourseDao { List getQueryCourses(Course course); int updateCourse(Course course); + + Course getCourseById(int id); + + int deleteCourse(int id); + + void insertCourse(Course course); } diff --git a/project2/src/main/java/cyou/chenx221/mapper/impl/CourseDaoImpl.java b/project2/src/main/java/cyou/chenx221/mapper/impl/CourseDaoImpl.java index 65517cc..53c8163 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/impl/CourseDaoImpl.java +++ b/project2/src/main/java/cyou/chenx221/mapper/impl/CourseDaoImpl.java @@ -30,4 +30,19 @@ public class CourseDaoImpl implements CourseDao { public int updateCourse(Course course) { return sqlSession.update("updateCourse", course); } + + @Override + public Course getCourseById(int id) { + return sqlSession.selectOne("getCourseById", id); + } + + @Override + public int deleteCourse(int id) { + return sqlSession.delete("deleteCourse", id); + } + + @Override + public void insertCourse(Course course) { + sqlSession.insert("insertCourse", course); + } } diff --git a/project2/src/main/java/cyou/chenx221/service/CourseService.java b/project2/src/main/java/cyou/chenx221/service/CourseService.java index 27fefa1..6cb72d5 100644 --- a/project2/src/main/java/cyou/chenx221/service/CourseService.java +++ b/project2/src/main/java/cyou/chenx221/service/CourseService.java @@ -27,4 +27,16 @@ public class CourseService { public int updateCourse(Course course) { return courseDao.updateCourse(course); } + + public Course getCourseById(int id) { + return courseDao.getCourseById(id); + } + + public int deleteCourse(int id) { + return courseDao.deleteCourse(id); + } + + public void insertCourse(Course course) { + courseDao.insertCourse(course); + } } diff --git a/project2/src/main/resources/mapper/CourseMapper.xml b/project2/src/main/resources/mapper/CourseMapper.xml index 5990dce..4b2e953 100644 --- a/project2/src/main/resources/mapper/CourseMapper.xml +++ b/project2/src/main/resources/mapper/CourseMapper.xml @@ -35,4 +35,19 @@ WHERE CourseID = #{courseID} + + + UPDATE course + SET removed = 1 + WHERE CourseID = #{id} + + + INSERT INTO course (CourseName, Description) + VALUES (#{courseName}, #{description}) + \ No newline at end of file diff --git a/project2/web/WEB-INF/views/courseopv2.jsp b/project2/web/WEB-INF/views/courseopv2.jsp index 195b863..4775d5f 100644 --- a/project2/web/WEB-INF/views/courseopv2.jsp +++ b/project2/web/WEB-INF/views/courseopv2.jsp @@ -298,7 +298,7 @@
-
@@ -307,7 +307,7 @@
-