Java 實戰項目之畢業設計管理系統的實現流程
一、項目簡述
功能包括: 該系統不錯分為學生,教師,管理員,教導主任四種角 色,包括學生管理,教師管理,學生選題,教師選題,主 任審核,管理員審核,開題報告,中期檢查,論文提交, 文件管理等等非常不錯。
二、項目運行
環境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
項目技術: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
用戶管理操作控制層:
/** * 用戶管理操作 */ @Controller @RequestMapping("/user") public class UserController { @Autowired private UserService userService; /** * 用戶添加頁面 * @return */ @GetMapping("/add") public String create() { return "user/add"; } /** * 用戶添加操作 * @param user * @return */ @PostMapping("/add") @ResponseBody public Map<String, Object> add(@RequestBody User user) { if(StringUtils.isEmpty(user.getUserName())){ return MapControl.getInstance().error("請填寫用戶名").getMap(); } if(StringUtils.isEmpty(user.getName())){ return MapControl.getInstance().error("請填寫名稱").getMap(); } if(StringUtils.isEmpty(user.getUserPwd())){ return MapControl.getInstance().error("請填寫密碼").getMap(); } int result = userService.create(user); if (result <= 0) { return MapControl.getInstance().error().getMap(); } return MapControl.getInstance().success().getMap(); } /** * 根據id刪除 * @param id * @return */ @PostMapping("/delete/{id}") @ResponseBody public Map<String, Object> delete(@PathVariable("id") Integer id) { int result = userService.delete(id); if (result <= 0) { return MapControl.getInstance().error().getMap(); } return MapControl.getInstance().success().getMap(); } //批量刪除 @PostMapping("/delete") @ResponseBody public Map<String, Object> delete(String ids) { int result = userService.delete(ids); if (result <= 0) { return MapControl.getInstance().error().getMap(); } return MapControl.getInstance().success().getMap(); } /** * 編輯用戶信息操作 * @param user * @return */ @PostMapping("/edit") @ResponseBody public Map<String, Object> edit(@RequestBody User user) { if(StringUtils.isEmpty(user.getUserName())){ return MapControl.getInstance().error("請填寫用戶名").getMap(); } if(StringUtils.isEmpty(user.getName())){ return MapControl.getInstance().error("請填寫名稱").getMap(); } if(StringUtils.isEmpty(user.getUserPwd())){ return MapControl.getInstance().error("請填寫密碼").getMap(); } int result = userService.update(user); if (result <= 0) { return MapControl.getInstance().error().getMap(); } return MapControl.getInstance().success().getMap(); } /** * 根據id查詢,跳轉修改頁面 * @param id * @param modelMap * @return */ @GetMapping("/edit/{id}") public String edit(@PathVariable("id") Integer id, ModelMap modelMap) { User user = userService.detail(id); modelMap.addAttribute("user", user); return "user/edit"; } //查詢所有 @PostMapping("/query") @ResponseBody public Map<String, Object> query(@RequestBody User user) { List<User> list = userService.query(user); Integer count = userService.count(user); return MapControl.getInstance().success().page(list, count).getMap(); } //跳轉列表頁面 @GetMapping("/list") public String list() { return "user/list"; } }
跳轉首頁判斷以及數據展示圖表:
@Controller public class IndexController { @Autowired UserService userService; @Autowired TeacherService teacherService; @Autowired StudentService studentService; @Autowired ClazzService clazzService; @Autowired SubjectService subjectService; @Autowired CourseService courseService; @Autowired SectionService sectionService; @Autowired ScoreService scoreService; //跳轉系統主頁 @GetMapping("/index") public String login() { return "index"; } //跳轉用戶基本信息頁面 @GetMapping("/info") public String info() { return "info"; } //跳轉修改密碼頁面 @GetMapping("/pwd") public String pwd() { return "pwd"; } //修改密碼 根據舊密碼來修改密碼 @PostMapping("/pwd") @ResponseBody public Map<String,Object> pwd(String sourcePwd,String newPwd,String type,Integer id) { //先判斷類型 if("1".equals(type)) { User user = userService.detail(id); //比較原密碼是否相同 註意:原密碼也要加密後再進行比較,因為數據庫中存儲的是加密後的密碼 if(user.getUserPwd().equals(MD5Utils.getMD5(sourcePwd))) { User entity = new User(); entity.setId(id); entity.setUserPwd(MD5Utils.getMD5(newPwd)); //主要要加密 int result = userService.update(entity); if(result <= 0) { return MapControl.getInstance().error().getMap(); } else { return MapControl.getInstance().success().getMap(); } } else { return MapControl.getInstance().error("原密碼錯誤").getMap(); } } if("2".equals(type)) { Teacher teacher = teacherService.detail(id); //比較原密碼 if(teacher.getTeacherPwd().equals(MD5Utils.getMD5(sourcePwd))) { Teacher entity = new Teacher(); entity.setId(id); entity.setTeacherPwd(MD5Utils.getMD5(newPwd)); int result = teacherService.update(entity); if(result <= 0) { return MapControl.getInstance().error().getMap(); } else { return MapControl.getInstance().success().getMap(); } } else { return MapControl.getInstance().error("原密碼錯誤").getMap(); } } if("3".equals(type)) { Student student = studentService.detail(id); //比較原密碼 if(student.getStuPwd().equals(MD5Utils.getMD5(sourcePwd))) { Student entity = new Student(); entity.setId(id); entity.setStuPwd(MD5Utils.getMD5(newPwd)); int result = studentService.update(entity); if(result <= 0) { return MapControl.getInstance().error().getMap(); } else { return MapControl.getInstance().success().getMap(); } } else { return MapControl.getInstance().error("原密碼錯誤").getMap(); } } return MapControl.getInstance().error().getMap(); } //跳轉系統主頁(數據概覽) @GetMapping("/main") public String main(ModelMap modelMap) { //1.系統數據概覽 List<Clazz> clazzes = clazzService.query(null); List<Subject> subjects = subjectService.query(null); List<Teacher> teachers = teacherService.query(null); List<Course> courses = courseService.query(null); List<Section> sections = sectionService.query(null); List<Student> students = studentService.query(null); modelMap.addAttribute("clazzCnt",clazzes.size()); modelMap.addAttribute("subjectCnt",subjects.size()); modelMap.addAttribute("teacherCnt",teachers.size()); modelMap.addAttribute("courseCnt",courses.size()); modelMap.addAttribute("studentCnt",students.size()); modelMap.addAttribute("sectionCnt",sections.size()); //2.班級學生數量 List<Map<String,Object>> mapList = new ArrayList<>(); for(Clazz clazz : clazzes) { Map<String,Object> map = new HashMap<>(); map.put("name",clazz.getClazzName()); //設置班級名稱 int cnt = 0; //統計學生數量 for(Student student : students) { if(student.getClazzId() == clazz.getId()) { cnt++; } } map.put("cnt",cnt); //設置學生數量 mapList.add(map); } modelMap.addAttribute("mapList",mapList); //3.查詢各科平均成績(根據專業查詢各科平均成績) List<HashMap> mapList2 = scoreService.queryAvgScoreBySection(); modelMap.addAttribute("mapList2",mapList2); return "main"; } }
公告管理控制器:
/** * 公告管理控制器 */ @Controller @RequestMapping("/notice") public class NoticeController { @Autowired private NoticeService noticeService; //跳轉添加頁面 @GetMapping("/add") public String add() { return "notice/add"; } /** * 公告添加 * @param notice * @return */ @PostMapping("/add") @ResponseBody public Map<String, Object> add(Notice notice, HttpServletRequest request) { if(StringUtils.isEmpty(notice.getTitle())){ return MapControl.getInstance().error("請填寫公告標題").getMap(); } if(StringUtils.isEmpty(notice.getContent())){ return MapControl.getInstance().error("請填寫公告內容").getMap(); } User user = (User) request.getSession().getAttribute("user"); notice.setAuthor(user.getUserName()); notice.setAuth("1"); int result = noticeService.create(notice); if (result <= 0) { //新增失敗 return MapControl.getInstance().error().getMap(); } return MapControl.getInstance().success().getMap(); } //根據id刪除 @PostMapping("/delete/{id}") @ResponseBody public Map<String, Object> delete(@PathVariable("id") Integer id) { int result = noticeService.delete(id); if (result <= 0) { return MapControl.getInstance().error().getMap(); } return MapControl.getInstance().success().getMap(); } //批量刪除 @PostMapping("/delete") @ResponseBody public Map<String, Object> delete(String ids) { int result = noticeService.delete(ids); if (result <= 0) { return MapControl.getInstance().error().getMap(); } return MapControl.getInstance().success().getMap(); } /** * 修改公告操作 * @param notice * @return */ @PostMapping("/edit") @ResponseBody public Map<String, Object> edit(@RequestBody Notice notice) { if(StringUtils.isEmpty(notice.getTitle())){ return MapControl.getInstance().error("請填寫公告標題").getMap(); } if(StringUtils.isEmpty(notice.getContent())){ return MapControl.getInstance().error("請填寫公告內容").getMap(); } int result = noticeService.update(notice); if (result <= 0) { return MapControl.getInstance().error().getMap(); } return MapControl.getInstance().success().getMap(); } //根據id查詢,跳轉修改頁面 @GetMapping("/edit/{id}") public String edit(@PathVariable Integer id, ModelMap modelMap) { //查詢要修改的老師 Notice notice = noticeService.detail(id); modelMap.addAttribute("notice", notice); return "notice/edit"; } //根據id查詢,跳轉添加頁面 @GetMapping("/look/{id}") public String look(@PathVariable Integer id, ModelMap modelMap) { Notice notice = noticeService.detail(id); modelMap.addAttribute("notice", notice); return "notice/look"; } //查詢所有 @PostMapping("/query") @ResponseBody public Map<String, Object> query(@RequestBody Notice notice) { List<Notice> list = noticeService.query(notice); Integer count = noticeService.count(notice); return MapControl.getInstance().success().put("data", list).put("count", count).getMap(); } //跳轉列表頁面 @GetMapping("/list") public String list() { return "notice/list"; } }
登陸用戶判斷業務控制層:
@Controller public class LoginController { @Autowired private UserService userService; @Autowired private TeacherService teacherService; @Autowired private StudentService studentService; //跳轉登錄頁面 @GetMapping("/login") public String login() { return "login"; } //登錄操作 @PostMapping("/login") @ResponseBody public Map<String, Object> login(String userName, String password, String captcha, String type, HttpSession session) { //判斷用戶名、密碼、用戶類型、驗證碼是否為空 if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(captcha) || StringUtils.isEmpty(type)) { return MapControl.getInstance().error("用戶名或密碼不能為空").getMap(); } //獲取系統生成的驗證碼 String _captcha = (String) session.getAttribute("captcha"); //先判斷驗證碼是否正確 if (!(captcha.toLowerCase()).equals(_captcha.toLowerCase())) { //驗證碼錯誤 return MapControl.getInstance().error("驗證碼錯誤").getMap(); } //判斷用戶類型 if ("1".equals(type)) { //管理員驗證登錄 User user = userService.login(userName, MD5Utils.getMD5(password)); //對密碼進行加密處理,因為數據庫中存儲的是加密後的密碼 if (user != null) { session.setAttribute("user", user); session.setAttribute("type", 1); return MapControl.getInstance().success().add("data", user).getMap(); } else { return MapControl.getInstance().error("用戶名或密碼錯誤").getMap(); } } if ("2".equals(type)) { //老師驗證登錄 Teacher teacher = teacherService.login(userName, MD5Utils.getMD5(password)); if (teacher != null) { session.setAttribute("user", teacher); session.setAttribute("type", "2"); return MapControl.getInstance().success().add("data", teacher).getMap(); } else { return MapControl.getInstance().error("用戶名或密碼錯誤").getMap(); } } if ("3".equals(type)) { //學生驗證登錄 Student student = studentService.login(userName, MD5Utils.getMD5(password)); if (student != null) { session.setAttribute("user", student); session.setAttribute("type", "3"); return MapControl.getInstance().success().add("data", student).getMap(); } else { return MapControl.getInstance().error("用戶名或密碼錯誤").getMap(); } } return MapControl.getInstance().getMap(); } }
到此這篇關於Java 實戰項目之畢業設計管理系統的實現流程的文章就介紹到這瞭,更多相關Java 畢業設計管理系統內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!