diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/StudentController.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/StudentController.class index 7ae77a1..7e57fc1 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/StudentController.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/StudentController.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/StudentDaoImpl.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/StudentDaoImpl.class index 6f01e68..953702a 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/StudentDaoImpl.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/StudentDaoImpl.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Student.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Student.class index c1a05b9..0f30cfe 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Student.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Student.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/StudentService.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/StudentService.class index 9ce1077..709e690 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/StudentService.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/StudentService.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/StudentMapper.xml b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/StudentMapper.xml index 130a60e..3cb708e 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/StudentMapper.xml +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/StudentMapper.xml @@ -4,9 +4,16 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > + - + + UPDATE student SET @@ -49,4 +58,11 @@ WHERE id = #{id} + + UPDATE student + SET removed = 1 + WHERE id = #{id} + + + diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/studentinfomodv2.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/studentinfomodv2.jsp index edfb498..e81b343 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/studentinfomodv2.jsp +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/studentinfomodv2.jsp @@ -179,7 +179,7 @@ - +
-
+
diff --git a/project2/src/main/java/cyou/chenx221/controller/StudentController.java b/project2/src/main/java/cyou/chenx221/controller/StudentController.java index 4b15c50..d5f6a31 100644 --- a/project2/src/main/java/cyou/chenx221/controller/StudentController.java +++ b/project2/src/main/java/cyou/chenx221/controller/StudentController.java @@ -114,15 +114,38 @@ public class StudentController { return "studentinfomodv2"; } - @PostMapping(value = "/delinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")//处理学生信息修改请求 + @PostMapping(value = "/delinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") public String UpdateModInfo(@RequestParam(value = "id", defaultValue = "-1", required = false) int id, Model model) { - Student student; - if (id <= -1) { - model.addAttribute("errorMessage", "ID异常,学生信息修改失败"); + Student temp = studentService.getStudentById(id); + if (id <= 0 || temp == null) { + model.addAttribute("errorMessage", "学生信息删除失败,可能是ID非法或者学生已删除"); } else { - student = new Student(id); - studentService.deleteStudent(student); +// 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", defaultValue = "null", required = false) String name, + @RequestParam(value = "birthday", defaultValue = "#{null}", required = false) Date birthday, + @RequestParam(value = "sex", defaultValue = "null", required = false) String sex, + @RequestParam(value = "phone", defaultValue = "null", required = false) String phone, + @RequestParam(value = "classes", defaultValue = "", required = false) String classes, + Model model) { + Student student; + if (name.equals("null")) name = null; + if (sex.equals("null")) sex = null; + if (phone.equals("null")) phone = null; + if (classes.equals("")) classes = null; + + if (id <= -1) { + model.addAttribute("errorMessage", "学生信息修改失败"); + } else { + student = new Student(id, name, sex, birthday, phone, classes); + studentService.updateStudent(student); model.addAttribute("successMessage", "学生信息修改成功"); } return "redirect:/student/modstep1"; diff --git a/project2/src/main/java/cyou/chenx221/mapper/StudentDao.java b/project2/src/main/java/cyou/chenx221/mapper/StudentDao.java index 72c04a9..e35fcab 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/StudentDao.java +++ b/project2/src/main/java/cyou/chenx221/mapper/StudentDao.java @@ -3,13 +3,12 @@ package cyou.chenx221.mapper; import cyou.chenx221.pojo.Student; import org.springframework.stereotype.Repository; -import java.util.Date; import java.util.List; @Repository public interface StudentDao { void insertStudent(Student student); - void deleteStudent(Student student); + void deleteStudent(int id); Student getStudentById(int studentId); List getAllStudents(); diff --git a/project2/src/main/java/cyou/chenx221/mapper/impl/StudentDaoImpl.java b/project2/src/main/java/cyou/chenx221/mapper/impl/StudentDaoImpl.java index 9eb0429..aebe2f4 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/impl/StudentDaoImpl.java +++ b/project2/src/main/java/cyou/chenx221/mapper/impl/StudentDaoImpl.java @@ -32,8 +32,8 @@ public class StudentDaoImpl implements StudentDao { } @Override - public void deleteStudent(Student student) { - sqlSession.delete("deleteStudent", student); + public void deleteStudent(int id) { + sqlSession.update("deleteStudent", id); } @Override diff --git a/project2/src/main/java/cyou/chenx221/pojo/Student.java b/project2/src/main/java/cyou/chenx221/pojo/Student.java index 5311827..d0f63ea 100644 --- a/project2/src/main/java/cyou/chenx221/pojo/Student.java +++ b/project2/src/main/java/cyou/chenx221/pojo/Student.java @@ -2,8 +2,6 @@ package cyou.chenx221.pojo; import org.springframework.format.annotation.DateTimeFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -17,17 +15,17 @@ public class Student { private String classes; private List classess; - private Integer removed; + private int removed; - public Student(Integer id) { + public Student(int id) { this.id = id; } - public Integer getRemoved() { + public int getRemoved() { return removed; } - public void setRemoved(Integer removed) { + public void setRemoved(int removed) { this.removed = removed; } diff --git a/project2/src/main/java/cyou/chenx221/service/StudentService.java b/project2/src/main/java/cyou/chenx221/service/StudentService.java index e0fda02..45ff4d5 100644 --- a/project2/src/main/java/cyou/chenx221/service/StudentService.java +++ b/project2/src/main/java/cyou/chenx221/service/StudentService.java @@ -19,8 +19,8 @@ public class StudentService { studentDao.insertStudent(student); } - public void deleteStudent(Student student) { - studentDao.deleteStudent(student); + public void deleteStudent(int id) { + studentDao.deleteStudent(id); } public Student getStudentById(int studentId) { diff --git a/project2/src/main/resources/mapper/StudentMapper.xml b/project2/src/main/resources/mapper/StudentMapper.xml index 130a60e..3cb708e 100644 --- a/project2/src/main/resources/mapper/StudentMapper.xml +++ b/project2/src/main/resources/mapper/StudentMapper.xml @@ -4,9 +4,16 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > + - + + UPDATE student SET @@ -49,4 +58,11 @@ WHERE id = #{id} + + UPDATE student + SET removed = 1 + WHERE id = #{id} + + + diff --git a/project2/web/WEB-INF/views/studentinfomodv2.jsp b/project2/web/WEB-INF/views/studentinfomodv2.jsp index edfb498..263cac6 100644 --- a/project2/web/WEB-INF/views/studentinfomodv2.jsp +++ b/project2/web/WEB-INF/views/studentinfomodv2.jsp @@ -179,22 +179,13 @@ - +
-
-
-
- - -
-
-
@@ -256,7 +247,7 @@
- +