From cc471c14783fb3204c03e412c7f49eea32406f17 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sun, 11 Jun 2023 11:20:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=88=A0=E9=99=A4=E3=80=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chenx221 --- .../controller/CourseController.class | Bin 3949 -> 4989 bytes .../cyou/chenx221/mapper/CourseDao.class | Bin 536 -> 679 bytes .../chenx221/mapper/impl/CourseDaoImpl.class | Bin 1462 -> 2068 bytes .../cyou/chenx221/service/CourseService.class | Bin 1148 -> 1541 bytes .../WEB-INF/classes/mapper/CourseMapper.xml | 15 ++++ .../chenx221/controller/CourseController.java | 77 ++++++++---------- .../java/cyou/chenx221/mapper/CourseDao.java | 6 ++ .../chenx221/mapper/impl/CourseDaoImpl.java | 15 ++++ .../cyou/chenx221/service/CourseService.java | 12 +++ .../main/resources/mapper/CourseMapper.xml | 15 ++++ project2/web/WEB-INF/views/courseopv2.jsp | 4 +- 11 files changed, 101 insertions(+), 43 deletions(-) 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 4bcea9a7efb959c737a66932eada8f5540a2a630..350b1ca736ac421f43e7771d329a2d0fa39b2171 100644 GIT binary patch literal 4989 zcmb_e>sJ$J9)2byBtpCp3W|tYx>`brqg1H{Z5PE0T~I5ERcq~#3^*DxaWVnft5xi} zwq4s@?JBL;YIV<^mbTlX)m}b&&i)++>8Jg;XZLis`@A!gkU*C0*|Ud`%)FQ1<$0dp z?|uLBuX|quSdUvJaG}Txw;vu9OPF_98BpYy67Q3@_Z(Iuri9{kT3j=ql~7a{?4AW5 zW_eNK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TC8(I#(@-w=$nLs!Hglm^-#wAPNG9v#<|m zVIR)IK5VH}p8*xTCB_qqw+k&C1 zcHs(!bYvJ>?=Tc8%uwh77B)OUWz8iAngm`EqEsxE4COb9z%b#heVWD zd7K?bMZvnQCcK;_1wvbjI0?|H*aTMKD9blRH4kDJd;TkgLYxBvaIkDM=RhP2ZX^qC zBnxiD0e2VXTAj~BdkZa!inBe?o;%LOMLDm7r?h0@_iXPTFMM8X=ST7~ESC?f`1xKm nwfvbPd&W!YOt1WF|984vxXw6Tc;E6C;L{Dh-z1H8uleBLl0bZj delta 1504 zcmbW1-ES0C7{;Ho^R=CwR-AQPwslK`xJtLJ6l%3gs{#cVC@PB7wt%Z!tg9`RE>#h9 zD6U`O@^~W&3C4?ZC5omLHQ*hIi64IiAU7l=UU`A~oHNTH3Er5@&UxqEbDsB{=l9Os z$X;u8fBNgY^8g0$$=B}BqA89Q0_MKi$w?PkJmBC#4=d3w3udqAkb#-C9drq#`Y~^^xQW2tD7=n<#E~W4jEI^RPY+3*D*=0G1*YxFLueT^(}$gX%Ei>rQdD%C#|4=g8@r22ZzK*EFM=VP=A7FLK`PHTPkfxlV&(Z?JH=LgoFVm_en26)G8o z*|vXWl`97@tMR3^T?&_<28-PZfZ1X$tS|cGg$8z7O=&C z<|}T*fWp*E>wys>9VPZLv@qLF1N#VjkVb4F-VvhRL))f^=pgNyLs{c2@IZrnqu#_@ z2y8AX;B8J&45|@>D&DCvsNztKK^2F&#L)9p2bg%5@ednmaC{F>|8k z^RuC`G&In#VkhB1WcF?XOEmAG6JO^3ad>KnMd&#mC`CE$oE$MDIDRGzXc8h||nvxy$efZx5kFF^6 z!%Dc#fAcN09K;=DdC6b=#y|za;Rg9J>gMI}qgdpE+X21*Ux5BMpBS47h&AH_UCw7O Oe8|K{1Q+(i$NvBvr1q=; 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 8931819b87abe7dd9ea33bbb4a38036878a9c851..63324dd9deeeb5f1d356b9ecd28e5531e3779cf3 100644 GIT binary patch delta 138 zcmbQivYeIc)W2Q(7#J9A86-Ax#W9NTrl*!T=a&{0r#e-7rZ6(dX?SW*+$$~5$iS15 znv+_R3Xx=FU;#>a0!1_Pic^b9CfhTrF@{Y}V=QK5n|zB=Lyv`#fscWofdNPhFbINa aAqHWfMNAALU{aJp3`nyvFfxcUFaQABNgGoD delta 52 zcmZ3^I)jDl)W2Q(7#J9A8H6@+#W7C4&sfOFJUNg_LyUomfe$Fb#K6xW0HoO%7#Rc^ F7yxN92~hw5 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 7328373f89ad8fb3c61ce5b7afd7e8feb6f1e7b2..b9adee57420bc9d1105fddd84cd921342c82c69c 100644 GIT binary patch delta 896 zcmaKp+fEZv6o&t`r!ZwYQwN$Bv9SoE_MnUhM5LZL2n?bHO*F;}t#;c$nwqo&iC2Ay z@iDxBc*G0BwXflgPhnhh$S}dgo4xj0`(NMw_u5}mA587%pC1PRZsYNuc0j!(#t24J zIt%Z%J6$>d-fn0(iwPCybezWp!r)eYr*5_C?WSe79odu}g1S?0ZOhtQLau0+*8Wjc zQ!r7|QAUL@(3LIu#;LU>VWt=pKXE$lE)AcIm1?iISXxzai7?{6QbyL3un2mC5snNz zdh9DYu40tX9~>kx#iGr2S9ZdOc%o??H+)fWpyDQ>;BJWQr(dLsM1iflFO}0nVzWUY zn~>lNheDCdc~N@m{#Ks%W^bLJwA z0=le9+yHF!&}Y_4^8y2E#XMvdBuB={Q&nF(=?PFY4tg78z7At*i3xipObv5VwQbB) ley(Ptt69w8lljtfDh~_Bb`YxCE~e{$X^Ew|zKXtI10T$q7pnjO 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 4e393981aa15466019f362f4d3b22cb586e41440..708b2f5e9ceaf9ce52e40f4e0c82295c9c575d8f 100644 GIT binary patch delta 675 zcmaKp%TB^j5QhIb1<|%(lnBuxRzWP_1;yLO7-iLkTc3c&V2mb!3!@1uAHa0uE10;D z=mr-)fD50<80WMIM68=R=gj3h|IB=j-sz9}R^66JmkpmD!1VO@mr$#~)c>rJG2{fsA!F~h;4HQVU6ubx_yg?#VG@coI zYxdMn09qf%bTE(&kecCb0y`%|ZnoUOo(>jV^ke zdUN2?B~V3;T1ak@-qfNK3TKoA_GAs{%se%~OS7~u%j%~;19ElvQb(zq^i(3PRc37b mlyJT!91Jm{@e?uT) 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 @@
-