Java 实战项目之毕业设计管理系统的实现流程
作者:qq_1334611189
读万卷书不如行万里路,只学书上的理论是远远不够的,只有在实战中才能获得能力的提升,本篇文章手把手带你用java+SSM+jsp+mysql+maven实现毕业设计管理系统,大家可以在过程中查缺补漏,提升水平
一、项目简述
功能包括: 该系统不错分为学生,教师,管理员,教导主任四种角 色,包括学生管理,教师管理,学生选题,教师选题,主 任审核,管理员审核,开题报告,中期检查,论文提交, 文件管理等等非常不错。
二、项目运行
环境配置: 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 毕业设计管理系统内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!