diff --git a/project2/README.md b/project2/README.md index 617a1bd..b71b806 100644 --- a/project2/README.md +++ b/project2/README.md @@ -45,29 +45,29 @@ - admin,teacher,student - /score - ~/all - - 学生成绩页 - - admin - - ~/all_t - - 学生成绩页(教师版) - - teacher + - 学生成绩页 [Get] + - admin,teacher,student + - scoreList|scoreList_t|scoreList_s - ~/infomodv2 - - 学生成绩修改页 - - admin - - ~/infomodv2_t - - 学生成绩修改页(教师版) - - teacher + - 学生成绩修改页 [Get] + - admin,teacher + - scoreopv2|scoreopv2_t - ~/query - - 学生成绩查询 + - 学生成绩查询 [Post] - admin,teacher + - scoreQueryResult|scoreQueryResult_t - ~/modinfo - - 学生成绩修改 + - 学生成绩修改 [Post] - admin + - *Redirect*.infomodv2 - ~/delinfo - - 学生成绩删除 + - 学生成绩删除 [Post] - admin + - *Redirect*.infomodv2 - ~/addinfo - - 学生成绩添加 + - 学生成绩添加 [Post] - admin,teacher + - *Redirect*.infomodv2|*Redirect*.infomodv2_t - /student - ~/all - 学生信息查询页 diff --git a/project2/src/main/java/cyou/chenx221/controller/ScoreController.java b/project2/src/main/java/cyou/chenx221/controller/ScoreController.java index eb4a9ef..cc15af6 100644 --- a/project2/src/main/java/cyou/chenx221/controller/ScoreController.java +++ b/project2/src/main/java/cyou/chenx221/controller/ScoreController.java @@ -33,21 +33,20 @@ public class ScoreController { if (username != null) { model.addAttribute("username", username); } - model.addAttribute("scores", scoreService.getAllScores()); - return "scoreList"; - } - - @GetMapping("/all_t") - public String getAllScoreT(Model model) { - String username = new UsernameHelper().getCurrentUsername(); - if (username != null) { - model.addAttribute("username", username); + String role = new UsernameHelper().getCurrentRole(); + if (role.equals("[ROLE_admin]")) { + model.addAttribute("scores", scoreService.getAllScores()); + return "score/scoreList"; + } else if (role.equals("[ROLE_teacher]")) { + model.addAttribute("scores", scoreService.getAllScores()); + return "score/scoreList_t"; + } else { + model.addAttribute("scores", scoreService.getQueryScore(scoreService.getStudentIdByUsername(username))); + return "score/scoreList_s"; } - model.addAttribute("scores", scoreService.getAllScores()); - return "scoreList_t"; } - @GetMapping("/infomodv2")//处理学生信息修改页 + @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) { @@ -58,26 +57,15 @@ public class ScoreController { model.addAttribute("scores", scoreService.getAllScores()); model.addAttribute("successMessage", successMessage); model.addAttribute("errorMessage", errorMessage); - - return "scoreopv2"; - } - - @GetMapping("/infomodv2_t")//处理学生信息修改页 - public String getInfoModv2T(@RequestParam(value = "successMessage", required = false, defaultValue = "null") String successMessage, - @RequestParam(value = "errorMessage", required = false, defaultValue = "null") String errorMessage, - Model model) { - String username = new UsernameHelper().getCurrentUsername(); - if (username != null) { - model.addAttribute("username", username); + String role = new UsernameHelper().getCurrentRole(); + if (role.equals("[ROLE_admin]")) + return "score/scoreopv2"; + else { + return "score/scoreopv2_t"; } - model.addAttribute("scores", scoreService.getAllScores()); - model.addAttribute("successMessage", successMessage); - model.addAttribute("errorMessage", errorMessage); - - return "scoreopv2_t"; } - @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 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 @@ -116,7 +104,12 @@ public class ScoreController { String download = new CsvHelper().generateScoreCSVFile(scores); model.addAttribute("download", download); model.addAttribute("scores", scores); - return "scoreQueryResult"; + String role = new UsernameHelper().getCurrentRole(); + if (role.equals("[ROLE_admin]")) + return "score/scoreQueryResult"; + else { + return "score/scoreQueryResult_t"; + } } @PostMapping(value = "/modinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8") @@ -160,7 +153,6 @@ public class ScoreController { 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, - @RequestParam(value = "sp1", defaultValue = "null", required = false) String sp1, Model model) { if (studentid <= 0) { model.addAttribute("errorMessage", "添加失败,学号非法"); @@ -177,9 +169,11 @@ public class ScoreController { model.addAttribute("errorMessage", "学生信息添加失败"); } } - if(sp1.equals("t")){ + String role = new UsernameHelper().getCurrentRole(); + if (role.equals("[ROLE_admin]")) + return "redirect:/score/infomodv2"; + else { return "redirect:/score/infomodv2_t"; } - 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 53a9202..3986606 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/ScoreDao.java +++ b/project2/src/main/java/cyou/chenx221/mapper/ScoreDao.java @@ -18,4 +18,8 @@ public interface ScoreDao { int deleteScore(int id); int insertScore(Score score); + + int getStudentIdByUsername(String username); + + List getQueryScore(int id); } 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 c3d9c5a..a954ed4 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/impl/ScoreDaoImpl.java +++ b/project2/src/main/java/cyou/chenx221/mapper/impl/ScoreDaoImpl.java @@ -46,4 +46,14 @@ public class ScoreDaoImpl implements ScoreDao { public int insertScore(Score score) { return sqlSession.insert("insertScore", score); } + + @Override + public int getStudentIdByUsername(String username) { + return sqlSession.selectOne("getStudentIdByUsername", username); + } + + @Override + public List getQueryScore(int id) { + return sqlSession.selectList("getQueryScore", id); + } } diff --git a/project2/src/main/java/cyou/chenx221/service/ScoreService.java b/project2/src/main/java/cyou/chenx221/service/ScoreService.java index 02bcda4..ca7a6e7 100644 --- a/project2/src/main/java/cyou/chenx221/service/ScoreService.java +++ b/project2/src/main/java/cyou/chenx221/service/ScoreService.java @@ -37,4 +37,13 @@ public class ScoreService { public int insertScore(Score score) { return scoreDao.insertScore(score); } + + //写这里可能位置不太合适... + public int getStudentIdByUsername(String username) { + return scoreDao.getStudentIdByUsername(username); + } + + public List getQueryScore(int id) { + return scoreDao.getQueryScore(id); + } } diff --git a/project2/src/main/resources/mapper/ScoreMapper.xml b/project2/src/main/resources/mapper/ScoreMapper.xml index a858bc5..2f49b29 100644 --- a/project2/src/main/resources/mapper/ScoreMapper.xml +++ b/project2/src/main/resources/mapper/ScoreMapper.xml @@ -67,9 +67,10 @@ UPDATE score @@ -80,4 +81,19 @@ 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/scoreList.jsp b/project2/web/WEB-INF/views/score/scoreList.jsp similarity index 100% rename from project2/web/WEB-INF/views/scoreList.jsp rename to project2/web/WEB-INF/views/score/scoreList.jsp diff --git a/project2/web/WEB-INF/views/scoreList_t.jsp b/project2/web/WEB-INF/views/score/scoreList_s.jsp similarity index 100% rename from project2/web/WEB-INF/views/scoreList_t.jsp rename to project2/web/WEB-INF/views/score/scoreList_s.jsp diff --git a/project2/web/WEB-INF/views/score/scoreList_t.jsp b/project2/web/WEB-INF/views/score/scoreList_t.jsp new file mode 100644 index 0000000..0e9ef91 --- /dev/null +++ b/project2/web/WEB-INF/views/score/scoreList_t.jsp @@ -0,0 +1,203 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + + + + + 成绩信息查看 + + + + + + + + + + +
+ +
+ + + + +
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
成绩ID学号学生姓名课程ID课程名成绩
${score.scoreID}${score.student.id}${score.student.name}${score.course.courseID}${score.course.courseName}${score.score}
+
+
+
+
+
+ + + + +
+
+ + + + + + + + + \ No newline at end of file diff --git a/project2/web/WEB-INF/views/scoreQueryResult.jsp b/project2/web/WEB-INF/views/score/scoreQueryResult.jsp similarity index 100% rename from project2/web/WEB-INF/views/scoreQueryResult.jsp rename to project2/web/WEB-INF/views/score/scoreQueryResult.jsp diff --git a/project2/web/WEB-INF/views/scoreQueryResult_t.jsp b/project2/web/WEB-INF/views/score/scoreQueryResult_t.jsp similarity index 100% rename from project2/web/WEB-INF/views/scoreQueryResult_t.jsp rename to project2/web/WEB-INF/views/score/scoreQueryResult_t.jsp diff --git a/project2/web/WEB-INF/views/scoreopv2.jsp b/project2/web/WEB-INF/views/score/scoreopv2.jsp similarity index 100% rename from project2/web/WEB-INF/views/scoreopv2.jsp rename to project2/web/WEB-INF/views/score/scoreopv2.jsp diff --git a/project2/web/WEB-INF/views/scoreopv2_t.jsp b/project2/web/WEB-INF/views/score/scoreopv2_t.jsp similarity index 100% rename from project2/web/WEB-INF/views/scoreopv2_t.jsp rename to project2/web/WEB-INF/views/score/scoreopv2_t.jsp