diff --git a/project2/.idea/webContexts.xml b/project2/.idea/webContexts.xml index 6494cc4..5b027d5 100644 --- a/project2/.idea/webContexts.xml +++ b/project2/.idea/webContexts.xml @@ -3,6 +3,7 @@ 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 f9904a0..7ae77a1 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/pojo/Student.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Student.class index ebc2151..c1a05b9 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/mapper/StudentMapper.xml b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/StudentMapper.xml index 1d03ad3..130a60e 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,7 +4,7 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > + diff --git a/project2/src/main/java/cyou/chenx221/controller/StudentController.java b/project2/src/main/java/cyou/chenx221/controller/StudentController.java index 820f112..4b15c50 100644 --- a/project2/src/main/java/cyou/chenx221/controller/StudentController.java +++ b/project2/src/main/java/cyou/chenx221/controller/StudentController.java @@ -28,19 +28,20 @@ public class StudentController { this.studentService = studentService; } - @GetMapping("/all") + + @GetMapping("/all")//学生信息查询(不带条件)(排除removed的学生) public String getAllStudents(Model model) { List students = studentService.getAllStudents(); model.addAttribute("students", students); return "studentList"; // 重定向到 dashboard 页面 } - @GetMapping("/queryinfo") + @GetMapping("/queryinfo")//处理访问学生信息查询 public String getQueryInfo(Model model) { - return "studentListQuery"; // 重定向到 dashboard 页面 + return "studentListQuery"; } - @PostMapping(value = "/query", produces = "application/x-www-form-urlencoded;charset=UTF-8") + @PostMapping(value = "/query", produces = "application/x-www-form-urlencoded;charset=UTF-8")//学生信息查询(带条件) public String getQueryStudents(@RequestParam(value = "name", defaultValue = "null", required = false) String name, @RequestParam(value = "birthday", defaultValue = "#{null}", required = false) Date birthday, @RequestParam(value = "inlineRadioOptions", defaultValue = "null", required = false) String option, @@ -48,13 +49,6 @@ public class StudentController { @RequestParam(value = "phone", defaultValue = "null", required = false) String phone, @RequestParam(value = "classes", defaultValue = "", required = false) List classes, Model model) { -// System.out.println("name: " + name); -// System.out.println("birthday: " + birthday); -// System.out.println("option: " + option); -// System.out.println("id: " + id); -// System.out.println("phone: " + phone); -// System.out.println("classes: " + classes); - List students; Student student; if (classes.size() == 0) { @@ -68,17 +62,15 @@ public class StudentController { student = new Student(classes); students = studentService.getQueryStudents2(student); } - - model.addAttribute("students", students); return "studentQueryResult"; } - @GetMapping("/modstep1") - public String getModStep1(@RequestParam(value = "successMessage", required = false , defaultValue = "null") String successMessage, - @RequestParam(value = "errorMessage" ,required = false , defaultValue = "null") String errorMessage, + @GetMapping("/modstep1")//处理学生信息修改页 + public String getModStep1(@RequestParam(value = "successMessage", required = false, defaultValue = "null") String successMessage, + @RequestParam(value = "errorMessage", required = false, defaultValue = "null") String errorMessage, Model model) { - List students = studentService.getAllStudents(); + List students = studentService.getAllStudents();//和前面显示全部学生一样,页面需要学生信息的显示 model.addAttribute("students", students); // 将消息添加到Model中 model.addAttribute("successMessage", successMessage); @@ -86,7 +78,7 @@ public class StudentController { return "studentMod"; } - @PostMapping(value = "/modinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") + @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 = "birthday", defaultValue = "#{null}", required = false) Date birthday, @RequestParam(value = "sex", defaultValue = "null", required = false) String sex, @@ -94,14 +86,6 @@ public class StudentController { @RequestParam(value = "phone", defaultValue = "null", required = false) String phone, @RequestParam(value = "classes", defaultValue = "", required = false) String classes, Model model) { - System.out.println("name: " + name); - System.out.println("birthday: " + birthday); - System.out.println("sex: " + sex); - System.out.println("id: " + id); - System.out.println("phone: " + phone); - System.out.println("classes: " + classes); -// - List students; Student student; if (name.equals("null")) name = null; if (sex.equals("null")) sex = null; @@ -117,32 +101,30 @@ public class StudentController { } return "redirect:/student/modstep1"; } -// students = studentService.getQueryStudents(student); + @GetMapping("/infomodv2")//处理学生信息修改页 + public String getInfoModv2(@RequestParam(value = "successMessage", required = false, defaultValue = "null") String successMessage, + @RequestParam(value = "errorMessage", required = false, defaultValue = "null") String errorMessage, + Model model) { + List students = studentService.getAllStudents();//和前面显示全部学生一样,页面需要学生信息的显示 + model.addAttribute("students", students); +// 将消息添加到Model中 + model.addAttribute("successMessage", successMessage); + model.addAttribute("errorMessage", errorMessage); + return "studentinfomodv2"; + } -// // 示例:处理查询学生信息的请求 -// @GetMapping("/{studentId}") -// public String getStudentById(@PathVariable int studentId) { -// // ... -// } -// -// // 示例:处理添加学生信息的请求 -// @PostMapping("/") -// public String addStudent(@RequestBody Student student) { -// // ... -// } -// -// // 示例:处理更新学生信息的请求 -// @PutMapping("/{studentId}") -// public String updateStudent(@PathVariable int studentId, @RequestBody Student student) { -// // ... -// } -// -// // 示例:处理删除学生信息的请求 -// @DeleteMapping("/{studentId}") -// public String deleteStudent(@PathVariable int studentId) { -// // ... -// } - - // ... + @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异常,学生信息修改失败"); + } else { + student = new Student(id); + studentService.deleteStudent(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 5e409a1..72c04a9 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/StudentDao.java +++ b/project2/src/main/java/cyou/chenx221/mapper/StudentDao.java @@ -9,7 +9,7 @@ import java.util.List; @Repository public interface StudentDao { void insertStudent(Student student); - void deleteStudent(int studentId); + void deleteStudent(Student student); 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 49d3fff..9eb0429 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(int studentId) { - sqlSession.delete("deleteStudent", studentId); + public void deleteStudent(Student student) { + sqlSession.delete("deleteStudent", student); } @Override diff --git a/project2/src/main/java/cyou/chenx221/pojo/Student.java b/project2/src/main/java/cyou/chenx221/pojo/Student.java index 849ef07..5311827 100644 --- a/project2/src/main/java/cyou/chenx221/pojo/Student.java +++ b/project2/src/main/java/cyou/chenx221/pojo/Student.java @@ -17,6 +17,20 @@ public class Student { private String classes; private List classess; + private Integer removed; + + public Student(Integer id) { + this.id = id; + } + + public Integer getRemoved() { + return removed; + } + + public void setRemoved(Integer removed) { + this.removed = removed; + } + public List getClassess() { return classess; } diff --git a/project2/src/main/java/cyou/chenx221/service/StudentService.java b/project2/src/main/java/cyou/chenx221/service/StudentService.java index 05be1a8..e0fda02 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(int studentId) { - studentDao.deleteStudent(studentId); + public void deleteStudent(Student student) { + studentDao.deleteStudent(student); } public Student getStudentById(int studentId) { diff --git a/project2/src/main/resources/mapper/StudentMapper.xml b/project2/src/main/resources/mapper/StudentMapper.xml index 1d03ad3..130a60e 100644 --- a/project2/src/main/resources/mapper/StudentMapper.xml +++ b/project2/src/main/resources/mapper/StudentMapper.xml @@ -4,7 +4,7 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > +