您好,登錄后才能下訂單哦!
這篇文章給大家介紹Java實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)的流程是怎樣的,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
功能包括: 用戶的登錄注冊(cè),學(xué)生信息管理,教師信息管理,班級(jí)信 息管理,采用mvcx項(xiàng)目架構(gòu),覆蓋增刪改查,包括學(xué)生, 教幣班級(jí)的信息導(dǎo)出上傳導(dǎo)入等等功能。
環(huán)境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
項(xiàng)目技術(shù): JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + maven等等。
/** * 用戶管理控制器 */ @RequestMapping("/user/") @Controller public class UserController { @Autowired private IUserService userService; @Autowired private IRoleService roleService; @Resource private ProcessEngineConfiguration configuration; @Resource private ProcessEngine engine; @GetMapping("/index") @ApiOperation("跳轉(zhuǎn)用戶頁(yè)接口") @PreAuthorize("hasRole('管理員')") public String index(String menuid,Model model){ List<Role> roles = queryAllRole(); model.addAttribute("roles",roles); model.addAttribute("menuid",menuid); //用戶首頁(yè) return "views/user/user_list"; } @GetMapping("/listpage") @ApiOperation("查詢用戶分頁(yè)數(shù)據(jù)接口") @ApiImplicitParams({ @ApiImplicitParam(name = "UserQuery", value = "用戶查詢對(duì)象", defaultValue = "userQuery對(duì)象") }) @ResponseBody @PreAuthorize("hasRole('管理員')") public PageList listpage(UserQuery userQuery){ return userService.listpage(userQuery); } //添加用戶 @PostMapping("/addUser") @ApiOperation("添加用戶接口") @ResponseBody public Map<String,Object> addUser(User user){ Map<String, Object> ret = new HashMap<>(); ret.put("code",-1); if(StringUtils.isEmpty(user.getUsername())){ ret.put("msg","請(qǐng)?zhí)顚懹脩裘?quot;); return ret; } if(StringUtils.isEmpty(user.getPassword())){ ret.put("msg","請(qǐng)?zhí)顚懨艽a"); return ret; } if(StringUtils.isEmpty(user.getEmail())){ ret.put("msg","請(qǐng)?zhí)顚戉]箱"); return ret; } if(StringUtils.isEmpty(user.getTel())){ ret.put("msg","請(qǐng)?zhí)顚懯謾C(jī)號(hào)"); return ret; } if(StringUtils.isEmpty(user.getHeadImg())){ ret.put("msg","請(qǐng)上傳頭像"); return ret; } if(userService.addUser(user)<=0) { ret.put("msg", "添加用戶失敗"); return ret; } ret.put("code",0); ret.put("msg","添加用戶成功"); return ret; } /** * 修改用戶信息操作 * @param user * @return */ @PostMapping("/editSaveUser") @ApiOperation("修改用戶接口") @PreAuthorize("hasRole('管理員')") @ResponseBody public Message editSaveUser(User user){ if(StringUtils.isEmpty(user.getUsername())){ return Message.error("請(qǐng)?zhí)顚懹脩裘?quot;); } if(StringUtils.isEmpty(user.getEmail())){ return Message.error("請(qǐng)?zhí)顚戉]箱"); } if(StringUtils.isEmpty(user.getTel())){ return Message.error("請(qǐng)?zhí)顚懯謾C(jī)號(hào)"); } try { userService.editSaveUser(user); return Message.success(); } catch (Exception e) { e.printStackTrace(); return Message.error("修改用戶信息失敗"); } } //添加用戶 @GetMapping("/deleteUser") @ApiOperation("刪除用戶接口") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "如:88",required = true) }) @PreAuthorize("hasRole('管理員')") @ResponseBody public AjaxResult deleteUser(@RequestParam(required = true) Long id){ AjaxResult ajaxResult = new AjaxResult(); try { userService.deleteUser(id); } catch (Exception e) { e.printStackTrace(); return new AjaxResult("刪除失敗"); } return ajaxResult; } @PostMapping(value="/deleteBatchUser") @ApiOperation("批量刪除用戶接口") @PreAuthorize("hasRole('管理員')") @ResponseBody public AjaxResult deleteBatchUser(String ids){ String[] idsArr = ids.split(","); List list = new ArrayList(); for(int i=0;i<idsArr.length;i++){ list.add(idsArr[i]); } try{ userService.batchRemove(list); return new AjaxResult(); }catch(Exception e){ return new AjaxResult("批量刪除失敗"); } } //查詢所有角色 public List<Role> queryAllRole(){ return roleService.queryAll(); } //添加用戶的角色 @PostMapping("/addUserRole") @ApiOperation("添加用戶角色接口") @ApiImplicitParams({ @ApiImplicitParam(name = "paramMap", value = "如:{userId:1,[1,2,3,4]]}") }) @ResponseBody public AjaxResult addUserRole(@RequestBody Map paramMap){ AjaxResult ajaxResult = new AjaxResult(); String userId = (String)paramMap.get("userId"); List roleIds = (List) paramMap.get("roleIds"); try { //添加用戶對(duì)應(yīng)的角色 roleService.addUserRole(userId,roleIds); return ajaxResult; }catch (Exception e){ e.printStackTrace(); return new AjaxResult("保存角色失敗"); } } //添加用戶 @RequestMapping("/regSaveUser") @ResponseBody public Long addTeacher(User user){ System.out.println("保存用戶...."+user); userService.addUser(user); //保存工作流程操作 IdentityService is = engine.getIdentityService(); // 添加用戶組 org.activiti.engine.identity.User userInfo = userService.saveUser(is, user.getUsername()); // 添加用戶對(duì)應(yīng)的組關(guān)系 Group stuGroup = new GroupEntityImpl(); stuGroup.setId("stuGroup"); Group tGroup = new GroupEntityImpl(); tGroup.setId("tGroup"); if(user.getType() == 2) { //保存老師組 userService.saveRel(is, userInfo, tGroup); } if(user.getType() == 3) { //保存學(xué)生組 userService.saveRel(is, userInfo, stuGroup); } Long userId = user.getId(); return userId; } /** * 修改密碼頁(yè)面 * @return */ @RequestMapping(value="/update_pwd",method=RequestMethod.GET) public String updatePwd(){ return "views/user/update_pwd"; } /** * 修改密碼操作 * @param oldPwd * @param newPwd * @return */ @ResponseBody @PostMapping("/update_pwd") public Message updatePassword(@RequestParam(name="oldPwd",required=true)String oldPwd, @RequestParam(name="newPwd",required=true)String newPwd){ String username = CommonUtils.getLoginUser().getUsername(); User userByUserName = userService.findUserByUserName(username); if(userByUserName!=null){ String password = userByUserName.getPassword(); BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); boolean matches = bCryptPasswordEncoder.matches(oldPwd, password); if(!matches){ return Message.error("舊密碼不正確");//true } userByUserName.setPassword(bCryptPasswordEncoder.encode(newPwd)); if(userService.editUserPassword(userByUserName)<=0){ return Message.error("密碼修改失敗"); } } return Message.success(); } /** * 清除緩存 * @param request * @param response * @return */ @ResponseBody @PostMapping("/clear_cache") public Message clearCache(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("Cache-Control","no-store"); response.setHeader("Pragrma","no-cache"); response.setDateHeader("Expires",0); return Message.success(); } }
@RequestMapping("/teacher") @Controller @Api(tags = "教師管理接口") public class TeacherController { @Autowired private IUserService userService; @Autowired private IClassesService classesService; @Resource private ProcessEngine engine; @Autowired private IOperaterLogService operaterLogService; //老師列表 @RequestMapping("/index") public String index(Model model){ //用戶首頁(yè) model.addAttribute("classes",classesService.queryAll()); return "views/teacher/teacher_list"; } @RequestMapping("/listpage") @ResponseBody public PageList listpage(UserQuery userQuery){ userQuery.setType(2L);//2表示老師 return userService.listpage(userQuery); } /** * 添加教師操作 * @param user * @return */ @PostMapping("/addTeacher") @ApiOperation("添加教師接口") @ResponseBody @PreAuthorize("hasRole('管理員')") public Message addTeacher(User user){ if(StringUtils.isEmpty(user.getUsername())){ return Message.error("請(qǐng)?zhí)顚懹脩裘?quot;); } if(StringUtils.isEmpty(user.getPassword())){ return Message.error("請(qǐng)?zhí)顚懨艽a"); } if(StringUtils.isEmpty(user.getEmail())){ return Message.error("請(qǐng)?zhí)顚戉]箱"); } if(StringUtils.isEmpty(user.getTel())){ return Message.error("請(qǐng)?zhí)顚懯謾C(jī)號(hào)"); } User userByUserName = userService.findUserByUserName(user.getUsername()); if(userByUserName!=null){ return Message.error("用戶名已存在"); } user.setType(2); if(userService.addUser(user)<=0){ return Message.error("教師添加失敗"); } //保存工作流程操作 IdentityService is = engine.getIdentityService(); // 添加用戶組 org.activiti.engine.identity.User userInfo = userService.saveUser(is, user.getUsername()); Group tGroup = new GroupEntityImpl(); tGroup.setId("tGroup"); userService.saveRel(is, userInfo, tGroup); operaterLogService.add("添加教師成功,教師名稱:"+user.getUsername()); return Message.success(); } /** * 修改教師操作 * @param user * @return */ @PostMapping("/editSaveStu") @ApiOperation("修改教師接口") @PreAuthorize("hasRole('管理員')") @ResponseBody public Message editSaveStu(User user){ if(StringUtils.isEmpty(user.getUsername())){ return Message.error("請(qǐng)?zhí)顚懹脩裘?quot;); } if(StringUtils.isEmpty(user.getEmail())){ return Message.error("請(qǐng)?zhí)顚戉]箱"); } if(StringUtils.isEmpty(user.getTel())){ return Message.error("請(qǐng)?zhí)顚懯謾C(jī)號(hào)"); } User userByUserName = userService.findUserByUserName(user.getUsername()); if(userByUserName!=null){ if(!userByUserName.getId().equals(user.getId())){ return Message.error("該用戶名已存在"); } } try { userService.editSaveUser(user); operaterLogService.add("編輯教師成功,教師名稱:"+user.getUsername()); return Message.success(); } catch (Exception e) { e.printStackTrace(); return Message.error("教師信息編輯失敗"); } } }
@RequestMapping("/student") @Controller @Api(tags = "學(xué)生管理接口") public class StudentController { @Autowired private IUserService userService; @Autowired private ICourseService courseService; @Autowired private IClassesService classesService; @Resource private ProcessEngine engine; @Autowired private IOperaterLogService operaterLogService; //老師列表 //后臺(tái)查詢學(xué)生列表 @RequestMapping("/index") public String index(Model model){ //用戶首頁(yè) model.addAttribute("courses",courseService.queryAll()); model.addAttribute("classes",classesService.queryAll()); return "views/student/student_list"; } @RequestMapping("/listpage") @ResponseBody public PageList listpage(UserQuery userQuery){ userQuery.setType(3L);//2表示老學(xué)生 return userService.listpage(userQuery); } /** * 添加學(xué)生操作 * @param user * @return */ @PostMapping("/addSaveStu") @ApiOperation("添加學(xué)生接口") @PreAuthorize("hasRole('管理員')") @ResponseBody public Message addSaveStudent(User user){ if(StringUtils.isEmpty(user.getUsername())){ return Message.error("請(qǐng)?zhí)顚懹脩裘?quot;); } if(StringUtils.isEmpty(user.getPassword())){ return Message.error("請(qǐng)?zhí)顚懨艽a"); } if(StringUtils.isEmpty(user.getEmail())){ return Message.error("請(qǐng)?zhí)顚戉]箱"); } if(StringUtils.isEmpty(user.getTel())){ return Message.error("請(qǐng)?zhí)顚懯謾C(jī)號(hào)"); } if(StringUtils.isEmpty(user.getStunum())){ return Message.error("請(qǐng)?zhí)顚憣W(xué)號(hào)"); } User userByUserName = userService.findUserByUserName(user.getUsername()); if(userByUserName!=null){ return Message.error("用戶名已存在"); } if(userService.findByStuNum(user.getStunum())!=null){ return Message.error("該學(xué)號(hào)已存在"); } user.setType(3); if(userService.addUser(user)<=0){ return Message.error("學(xué)生添加失敗"); } //保存工作流程操作 IdentityService is = engine.getIdentityService(); // 添加用戶組 org.activiti.engine.identity.User userInfo = userService.saveUser(is, user.getUsername()); // 添加用戶對(duì)應(yīng)的組關(guān)系 Group stuGroup = new GroupEntityImpl(); stuGroup.setId("stuGroup"); userService.saveRel(is, userInfo, stuGroup); operaterLogService.add("添加學(xué)生成功,學(xué)生名稱:"+user.getUsername()); return Message.success(); } //修改用戶editSaveUser @PostMapping("/editSaveStu") @ApiOperation("修改學(xué)生接口") @PreAuthorize("hasRole('管理員')") @ResponseBody public Message editSaveStu(User user){ if(StringUtils.isEmpty(user.getUsername())){ return Message.error("請(qǐng)?zhí)顚懹脩裘?quot;); } if(StringUtils.isEmpty(user.getEmail())){ return Message.error("請(qǐng)?zhí)顚戉]箱"); } if(StringUtils.isEmpty(user.getTel())){ return Message.error("請(qǐng)?zhí)顚懯謾C(jī)號(hào)"); } User userByUserName = userService.findUserByUserName(user.getUsername()); if(userByUserName!=null){ if(!userByUserName.getId().equals(user.getId())){ return Message.error("該用戶名已存在"); } } try { userService.editSaveUser(user); operaterLogService.add("編輯學(xué)生成功,學(xué)生名稱:"+user.getUsername()); return Message.success(); } catch (Exception e) { e.printStackTrace(); return Message.error("學(xué)生編輯失敗"); } } //editSaveStuXk @PostMapping("/editSaveStuXk") @ApiOperation("修改用戶接口") @ApiImplicitParams({ @ApiImplicitParam(name = "User", value = "學(xué)生選課") }) @ResponseBody public AjaxResult editSaveStuXk(User user){ try { userService.editSaveXk(user); operaterLogService.add("修改學(xué)生選課成功,學(xué)生名稱:"+user.getUsername()); return new AjaxResult(); } catch (Exception e) { e.printStackTrace(); } return new AjaxResult("修改失敗"); } }
關(guān)于Java實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)的流程是怎樣的就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。