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 b148a0b..661bae2 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/controller/ScoreController.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/ScoreController.class index 3fb6a87..209f116 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/ScoreController.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/ScoreController.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/helper/CsvHelper.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/helper/CsvHelper.class index 82bd420..0fb25b9 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/helper/CsvHelper.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/helper/CsvHelper.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/ScoreDao.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/ScoreDao.class index 905e96b..29e9e0d 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/ScoreDao.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/ScoreDao.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/ScoreDaoImpl.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/ScoreDaoImpl.class index f261df3..e8fad18 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/ScoreDaoImpl.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/ScoreDaoImpl.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Score.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Score.class index 01c2858..ee6c732 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Score.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Score.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/ScoreService.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/ScoreService.class index 343d848..0ff5fbf 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/ScoreService.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/ScoreService.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/ScoreMapper.xml b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/ScoreMapper.xml index 840fe21..a858bc5 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/ScoreMapper.xml +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/ScoreMapper.xml @@ -55,5 +55,29 @@ - + + UPDATE score + + + Score = #{score} + + + WHERE ScoreID = #{scoreID}; + + + + UPDATE score + SET invalid = 1 + WHERE ScoreID = #{id}; + + + INSERT INTO score (Score, StudentID, CourseID) + VALUES (#{score}, #{student.id}, #{course.courseID}); + \ No newline at end of file diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/spring-security.xml b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/spring-security.xml index 55b44eb..af4a99b 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/spring-security.xml +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/spring-security.xml @@ -25,6 +25,7 @@ +
+ <%-- 查询--%>
@@ -258,8 +259,10 @@
- - + +
@@ -276,6 +279,7 @@
+ <%-- 修改--%>
@@ -292,9 +296,9 @@
- - +
@@ -310,6 +314,7 @@
+ <%-- 删除--%>
@@ -334,6 +339,7 @@
+ <%-- 添加--%>
diff --git a/project2/src/main/java/cyou/chenx221/controller/CourseController.java b/project2/src/main/java/cyou/chenx221/controller/CourseController.java index ee2c862..bc37fac 100644 --- a/project2/src/main/java/cyou/chenx221/controller/CourseController.java +++ b/project2/src/main/java/cyou/chenx221/controller/CourseController.java @@ -52,7 +52,7 @@ public class CourseController { } @PostMapping(value = "/delinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") - public String UpdateModInfo(@RequestParam(value = "id") int id, + public String DeleteCourseInfo(@RequestParam(value = "id") int id, Model model) { Course temp = courseService.getCourseById(id); if (id <= 0 || temp == null) { diff --git a/project2/src/main/java/cyou/chenx221/controller/ScoreController.java b/project2/src/main/java/cyou/chenx221/controller/ScoreController.java index c1588da..cc60157 100644 --- a/project2/src/main/java/cyou/chenx221/controller/ScoreController.java +++ b/project2/src/main/java/cyou/chenx221/controller/ScoreController.java @@ -53,15 +53,15 @@ public class ScoreController { } @PostMapping(value = "/query", produces = "application/x-www-form-urlencoded;charset=UTF-8")//学生信息查询(带条件) - public String getQueryCourses(@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 { + public String getQueryScores(@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 { //username helper start String username = new UsernameHelper().getCurrentUsername(); @@ -93,4 +93,64 @@ public class ScoreController { model.addAttribute("scores", scores); return "scoreQueryResult"; } + + @PostMapping(value = "/modinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") + public String UpdateScoreInfo(@RequestParam(value = "score", defaultValue = "-1", required = false) int score, + @RequestParam(value = "id", defaultValue = "-1", required = false) int id,//成绩ID + Model model) { + if (id <= 0) { + model.addAttribute("errorMessage", "修改失败,ID非法"); + } else if (score > 100 || score < 0) { + model.addAttribute("errorMessage", "修改失败,分数非法"); + } else { + Score score1 = new Score(id, score); + int status_code = scoreService.updateScore(score1); + if (status_code == 1) { + model.addAttribute("successMessage", "修改成功"); + } else { + model.addAttribute("errorMessage", "修改失败,可能是成绩不存在"); + } + } + return "redirect:/score/infomodv2"; + } + + @PostMapping(value = "/delinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") + public String DeleteScoreInfo(@RequestParam(value = "id") int id, //成绩ID + Model model) { + Score temp = scoreService.getScoreById(id); + if (id <= 0 || temp == null) { + model.addAttribute("errorMessage", "成绩信息删除失败,可能是ID非法或者成绩已删除"); + } else { + int status_code = scoreService.deleteScore(id); + if (status_code == 1) { + model.addAttribute("successMessage", "学生信息删除成功"); + } else { + model.addAttribute("errorMessage", "学生信息删除异常"); + } + } + return "redirect:/score/infomodv2"; + } + + @PostMapping(value = "/addinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") + public String InsertCourseInfo(@RequestParam(value = "studentid", defaultValue = "-1", required = false) int studentid, + @RequestParam(value = "courseid", defaultValue = "-1", required = false) int courseid, + @RequestParam(value = "score", defaultValue = "-1", required = false) int score, + Model model) { + if(studentid<=0){ + model.addAttribute("errorMessage", "添加失败,学号非法"); + } else if (courseid<=0) { + model.addAttribute("errorMessage", "添加失败,课程ID非法"); + } else if(score>100||score<0){ + model.addAttribute("errorMessage", "添加失败,分数非法"); + } else { + Score score1 = new Score(new Student(studentid), new Course(courseid), score); + int status_code = scoreService.insertScore(score1); + if (status_code == 1) { + model.addAttribute("successMessage", "学生信息添加成功"); + } else { + model.addAttribute("errorMessage", "学生信息添加失败"); + } + } + return "redirect:/score/infomodv2"; + } } diff --git a/project2/src/main/java/cyou/chenx221/mapper/ScoreDao.java b/project2/src/main/java/cyou/chenx221/mapper/ScoreDao.java index 563e492..53a9202 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/ScoreDao.java +++ b/project2/src/main/java/cyou/chenx221/mapper/ScoreDao.java @@ -10,4 +10,12 @@ public interface ScoreDao { List getAllScore(); List getQueryScores(Score score); + + int updateScore(Score score); + + Score getScoreById(int id); + + int deleteScore(int id); + + int insertScore(Score score); } diff --git a/project2/src/main/java/cyou/chenx221/mapper/impl/ScoreDaoImpl.java b/project2/src/main/java/cyou/chenx221/mapper/impl/ScoreDaoImpl.java index ac44ab7..c3d9c5a 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/impl/ScoreDaoImpl.java +++ b/project2/src/main/java/cyou/chenx221/mapper/impl/ScoreDaoImpl.java @@ -26,4 +26,24 @@ public class ScoreDaoImpl implements ScoreDao { public List getQueryScores(Score score) { return sqlSession.selectList("getQueryScores", score); } + + @Override + public int updateScore(Score score) { + return sqlSession.update("updateScore", score); + } + + @Override + public Score getScoreById(int id) { + return sqlSession.selectOne("getScoreById",id); + } + + @Override + public int deleteScore(int id) { + return sqlSession.update("deleteScore", id); + } + + @Override + public int insertScore(Score score) { + return sqlSession.insert("insertScore", score); + } } diff --git a/project2/src/main/java/cyou/chenx221/pojo/Score.java b/project2/src/main/java/cyou/chenx221/pojo/Score.java index 837b881..f7ae8e3 100644 --- a/project2/src/main/java/cyou/chenx221/pojo/Score.java +++ b/project2/src/main/java/cyou/chenx221/pojo/Score.java @@ -31,6 +31,12 @@ public class Score { this.max = max; } + public Score(Student student, Course course, Integer score) { + this.student = student; + this.course = course; + this.score = score; + } + public Integer getMin() { return min; } diff --git a/project2/src/main/java/cyou/chenx221/service/ScoreService.java b/project2/src/main/java/cyou/chenx221/service/ScoreService.java index bf4e9ef..02bcda4 100644 --- a/project2/src/main/java/cyou/chenx221/service/ScoreService.java +++ b/project2/src/main/java/cyou/chenx221/service/ScoreService.java @@ -14,6 +14,14 @@ public class ScoreService { this.scoreDao = scoreDao; } + public int deleteScore(int id) { + return scoreDao.deleteScore(id); + } + + public Score getScoreById(int id) { + return scoreDao.getScoreById(id); + } + public List getAllScores() { return scoreDao.getAllScore(); } @@ -21,4 +29,12 @@ public class ScoreService { public List getQueryScores(Score score) { return scoreDao.getQueryScores(score); } + + public int updateScore(Score score) { + return scoreDao.updateScore(score); + } + + public int insertScore(Score score) { + return scoreDao.insertScore(score); + } } diff --git a/project2/src/main/resources/mapper/ScoreMapper.xml b/project2/src/main/resources/mapper/ScoreMapper.xml index 840fe21..a858bc5 100644 --- a/project2/src/main/resources/mapper/ScoreMapper.xml +++ b/project2/src/main/resources/mapper/ScoreMapper.xml @@ -55,5 +55,29 @@ - + + UPDATE score + + + Score = #{score} + + + WHERE ScoreID = #{scoreID}; + + + + UPDATE score + SET invalid = 1 + WHERE ScoreID = #{id}; + + + INSERT INTO score (Score, StudentID, CourseID) + VALUES (#{score}, #{student.id}, #{course.courseID}); + \ No newline at end of file diff --git a/project2/web/WEB-INF/views/scoreopv2.jsp b/project2/web/WEB-INF/views/scoreopv2.jsp index bd04123..3eb60cd 100644 --- a/project2/web/WEB-INF/views/scoreopv2.jsp +++ b/project2/web/WEB-INF/views/scoreopv2.jsp @@ -186,6 +186,7 @@
+ <%-- 查询--%>
@@ -258,8 +259,10 @@
- - + +
@@ -276,6 +279,7 @@
+ <%-- 修改--%>
@@ -292,9 +296,9 @@
- - +
@@ -310,6 +314,7 @@
+ <%-- 删除--%>
@@ -334,6 +339,7 @@
+ <%-- 添加--%>