Java实现火车票预订系统的代码怎么写(java,开发技术)

时间:2024-04-29 09:07:31 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

一、项目运行

环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP + Servlert + html+ css + JavaScript + JQuery + Ajax 等等;

二、效果图

Java实现火车票预订系统的代码怎么写

Java实现火车票预订系统的代码怎么写

Java实现火车票预订系统的代码怎么写

Java实现火车票预订系统的代码怎么写

Java实现火车票预订系统的代码怎么写

Java实现火车票预订系统的代码怎么写

Java实现火车票预订系统的代码怎么写

三、核心代码

个人中心Controller

/***个人中心Controller*/@ControllerpublicclassUserInforController{@AutowiredprivateUserInforServiceImpluserInforService=null;/***修改密码操作*@paramoldPassword*@paramnewPassword*@paramrePassword*@paramhttpSession*@return*/@RequestMapping("changePassword.do")@ResponseBodypublicMap<String,String>changePassword(StringoldPassword,StringnewPassword,StringrePassword,HttpSessionhttpSession){HashMap<String,String>map=newHashMap<String,String>();if(newPassword.equals(rePassword)){SystemManageradmin=(SystemManager)httpSession.getAttribute("admin");StringencodeByMD5=MD5Utils.encodeByMD5(oldPassword);if(encodeByMD5.equals(admin.getSmPassword())){StringnewPasswords=MD5Utils.encodeByMD5(newPassword);admin.setSmPassword(newPasswords);userInforService.updateSystemManagePassword(admin.getSmId(),admin);map.put("type","success");map.put("msg","密码修改成功");returnmap;}else{map.put("type","error");map.put("msg","原密码错误");returnmap;}}else{map.put("type","error");map.put("msg","两次密码不一致");returnmap;}}/***员工修改个人密码*@paramoldPassword*@paramnewPassword*@paramrePassword*@paramhttpSession*@return*/@RequestMapping("changeEmployeePassword.do")@ResponseBodypublicMap<String,String>changeEmployeePassword(StringoldPassword,StringnewPassword,StringrePassword,HttpSessionhttpSession){HashMap<String,String>map=newHashMap<String,String>();if(newPassword.equals(rePassword)){Integereid=(Integer)httpSession.getAttribute("employeeId");try{userInforService.updateEmployeePassword(eid,oldPassword,newPassword);map.put("type","success");map.put("msg","密码修改成功");returnmap;}catch(CustomExceptione){map.put("type","error");map.put("msg","原密码错误");returnmap;}}else{map.put("type","error");map.put("msg","两次密码不一致");returnmap;}}/***查看个人信息*@paramhttpSession*@return*/@RequestMapping("inforEmployee.do")public@ResponseBodyEmployeeCustomVogetInforEmployee(HttpSessionhttpSession){Integerid=(Integer)httpSession.getAttribute("employeeId");EmployeeCustomVoemployeeCustomVo=userInforService.getInforEmployee(id);returnemployeeCustomVo;}/***修改个人信息*@paramhttpSession*@paramemployee*@return*/@ResponseBody@RequestMapping("updateInforEmployee.do")publicMessageupdateInforEmployee(HttpSessionhttpSession,Employeeemployee){Integerid=(Integer)httpSession.getAttribute("employeeId");employee.seteId(id);if(userInforService.updateEmploueeById(id,employee)<=0){ returnMessage.error("修改信息失败");}returnMessage.success();}/***个人工资信息*@parampageNum*@paramlimit*@paramyear*@paramhttpSession*@return*@throwsException*/@RequestMapping("employeeSalaryList.do")@ResponseBodypublicEmployeeSalaryVOfindSelective(@RequestParam(value="page",defaultValue="1")intpageNum,@RequestParam(value="limit",defaultValue="10")intlimit,@RequestParam(value="year",defaultValue="1")Stringyear,HttpSessionhttpSession)throwsException{IntegereId=(Integer)httpSession.getAttribute("employeeId");//pageNum:起始页面pageSize:每页的大小PageHelper.startPage(pageNum,limit);//查找条件,一定要紧跟在startPage后List<Salary>salaryList=userInforService.getEmployeeSalaryList(eId,year);PageInfopageResult=newPageInfo(salaryList);//设置前台需要的数据EmployeeSalaryVOemployeeSalaryVO=newEmployeeSalaryVO();employeeSalaryVO.setCode(0);employeeSalaryVO.setMsg("");employeeSalaryVO.setCount((int)pageResult.getTotal());employeeSalaryVO.setData(pageResult.getList());returnemployeeSalaryVO;}}

管理员和员工登陆控制

/***@Author:admin*@Description:管理员和员工登陆控制**/@ControllerpublicclassLoginController{@AutowiredprivateLoginServiceImplloginService=null;/***@Author:admin*@Description:验证码变更*@Date:14:332021/10/5*@Param:[request,response]*@Return:void**/@RequestMapping(value="/changeCode.do")@ResponseBodypublicvoidgetIdentifyingCode(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{//验证码存储在session的identifyingCode,属性中CaptchaUtil.outputCaptcha(request,response);}//获取员工登陆界面@RequestMapping("/")publicStringgetLoginPage(){return"employee/login.html";}//获取管理员登陆界面@RequestMapping("/admin.do")publicStringgetAdminLoginPage(HttpServletRequestrequest){ StringrealPath=request.getServletContext().getRealPath("/"); request.getSession().setAttribute("realPath",realPath);return"admin/adminLogin.html";}/***员工登录操作*@parammodel*@paramhttpSession*@paramusername*@parampassword*@paramidentifyingcode*@return*/@RequestMapping(value="/employeeLogin.do")@ResponseBodypublicMessageemployeeLogin(HttpSessionhttpSession,Stringusername,Stringpassword,Stringidentifyingcode){ if(StringUtils.isEmpty(username)){ returnMessage.error("请填写工号"); } if(StringUtils.isEmpty(password)){ returnMessage.error("请填写密码"); } if(StringUtils.isEmpty(identifyingcode)){ returnMessage.error("请填写验证码"); }Stringcode=(String)httpSession.getAttribute("identifyingCode");if(!identifyingcode.equalsIgnoreCase(code)){ returnMessage.error("验证码错误");}Employeeemployee=loginService.findEmployeeByIdAndPassword(username,password);if(employee==null){ returnMessage.error("工号或密码错误");}httpSession.setAttribute("employeeId",employee.geteId());returnMessage.success("员工登录成功");}@RequestMapping(value="/loginSuccess.do")publicStringloginSucceses(Modelmodel)throwsException{return"employee/index.html";}/***管理员登录操作*@parammodel*@paramhttpSession*@paramusername*@parampassword*@paramidentifyingcode*@return*/@RequestMapping(value="/adminLogin.do")@ResponseBodypublicMessageadminLogin(HttpSessionhttpSession,Stringusername,Stringpassword,Stringidentifyingcode){ if(StringUtils.isEmpty(username)){ returnMessage.error("请填写账号"); } if(StringUtils.isEmpty(password)){ returnMessage.error("请填写密码"); } if(StringUtils.isEmpty(identifyingcode)){ returnMessage.error("请填写验证码"); }Stringcode=(String)httpSession.getAttribute("identifyingCode");if(identifyingcode.equalsIgnoreCase(code)){SystemManagermanager=loginService.findSystemManagerByIdAndPassword(username,password);if(manager==null){ returnMessage.error("账号或密码错误");}//保存到sessionhttpSession.setAttribute("admin",manager);returnMessage.success("登录成功");}else{ returnMessage.error("验证码错误");}}@RequestMapping(value="/getAdminAccount.do")@ResponseBodypublicStringgetAdminAccount(HttpSessionhttpSession){SystemManagersystemManager=(SystemManager)httpSession.getAttribute("admin");//SystemManagermanager=loginService.findSystemManagerById(id);returnsystemManager.getSmAccount();}@RequestMapping(value="/getEmployeeAccount.do")@ResponseBodypublicMap<String,String>getEmployeeAccount(HttpSessionhttpSession){Integerid=(Integer)httpSession.getAttribute("employeeId");Employeeemployee=loginService.findEmployeeById(id);HashMap<String,String>map=newHashMap<String,String>();map.put("account",employee.geteAccount());map.put("name",employee.geteName());returnmap;}@RequestMapping(value="/logout.do")publicStringlogout(HttpSessionhttpSession){httpSession.removeAttribute("employeeId");return"redirect:/";}@RequestMapping(value="/logoutAdmin.do")publicStringlogoutAdmin(HttpSessionhttpSession){httpSession.removeAttribute("admin");return"redirect:/admin.do";}}

用户管理操作

/***用户管理操作*/@Controller@RequestMapping("/user")publicclassUserController{@AutowiredprivateUserServiceuserService;/***用户添加页面*@return*/@GetMapping("/add")publicStringcreate(){return"user/add";}/***用户添加操作*@paramuser*@return*/@PostMapping("/add")@ResponseBodypublicMap<String,Object>add(@RequestBodyUseruser){if(StringUtils.isEmpty(user.getUserName())){returnMapControl.getInstance().error("请填写用户名").getMap();}if(StringUtils.isEmpty(user.getName())){returnMapControl.getInstance().error("请填写名称").getMap();}if(StringUtils.isEmpty(user.getUserPwd())){returnMapControl.getInstance().error("请填写密码").getMap();}intresult=userService.create(user);if(result<=0){returnMapControl.getInstance().error().getMap();}returnMapControl.getInstance().success().getMap();}/***根据id删除*@paramid*@return*/@PostMapping("/delete/{id}")@ResponseBodypublicMap<String,Object>delete(@PathVariable("id")Integerid){intresult=userService.delete(id);if(result<=0){returnMapControl.getInstance().error().getMap();}returnMapControl.getInstance().success().getMap();}//批量删除@PostMapping("/delete")@ResponseBodypublicMap<String,Object>delete(Stringids){intresult=userService.delete(ids);if(result<=0){returnMapControl.getInstance().error().getMap();}returnMapControl.getInstance().success().getMap();}/***编辑用户信息操作*@paramuser*@return*/@PostMapping("/edit")@ResponseBodypublicMap<String,Object>edit(@RequestBodyUseruser){if(StringUtils.isEmpty(user.getUserName())){returnMapControl.getInstance().error("请填写用户名").getMap();}if(StringUtils.isEmpty(user.getName())){returnMapControl.getInstance().error("请填写名称").getMap();}if(StringUtils.isEmpty(user.getUserPwd())){returnMapControl.getInstance().error("请填写密码").getMap();}intresult=userService.update(user);if(result<=0){returnMapControl.getInstance().error().getMap();}returnMapControl.getInstance().success().getMap();}/***根据id查询,跳转修改页面*@paramid*@parammodelMap*@return*/@GetMapping("/edit/{id}")publicStringedit(@PathVariable("id")Integerid,ModelMapmodelMap){Useruser=userService.detail(id);modelMap.addAttribute("user",user);return"user/edit";}//查询所有@PostMapping("/query")@ResponseBodypublicMap<String,Object>query(@RequestBodyUseruser){List<User>list=userService.query(user);Integercount=userService.count(user);returnMapControl.getInstance().success().page(list,count).getMap();}//跳转列表页面@GetMapping("/list")publicStringlist(){return"user/list";}}
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:Java实现火车票预订系统的代码怎么写的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:如何使用Jitpack发布开源Java库下一篇:

8 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18