Java实战之火车票预订系统的实现
目录
- 一、项目运行
- 二、效果图
- 三、核心代码
- 个人中心Controller
- 管理员和员工登陆控制
- 用户管理操作
一、项目运行 环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP + Servlert + html+ css + JavaScript + JQuery + Ajax 等等;
二、效果图
文章图片
文章图片
文章图片
【Java实战之火车票预订系统的实现】
文章图片
文章图片
文章图片
文章图片
三、核心代码
个人中心Controller
/** * 个人中心Controller */@Controllerpublic class UserInforController { @Autowiredprivate UserInforServiceImpl userInforService = null; /*** 修改密码操作* @param oldPassword* @param newPassword* @param rePassword* @param httpSession* @return*/@RequestMapping("changePassword.do")@ResponseBodypublic Map changePassword(String oldPassword, String newPassword,String rePassword, HttpSession httpSession){HashMap map = new HashMap(); if (newPassword.equals(rePassword)){SystemManager admin = (SystemManager) httpSession.getAttribute("admin"); String encodeByMD5 = MD5Utils.encodeByMD5(oldPassword); if (encodeByMD5.equals(admin.getSmPassword())){String newPasswords = MD5Utils.encodeByMD5(newPassword); admin.setSmPassword(newPasswords); userInforService.updateSystemManagePassword(admin.getSmId(),admin); map.put("type","success"); map.put("msg","密码修改成功"); return map; }else{map.put("type","error"); map.put("msg","原密码错误"); return map; }}else{map.put("type","error"); map.put("msg","两次密码不一致"); return map; }}/*** 员工修改个人密码* @param oldPassword* @param newPassword* @param rePassword* @param httpSession* @return*/@RequestMapping("changeEmployeePassword.do")@ResponseBodypublic Map changeEmployeePassword(String oldPassword, String newPassword,String rePassword, HttpSession httpSession){HashMap map = new HashMap(); if (newPassword.equals(rePassword)){Integer eid = (Integer) httpSession.getAttribute("employeeId"); try {userInforService.updateEmployeePassword(eid, oldPassword, newPassword); map.put("type","success"); map.put("msg","密码修改成功"); return map; } catch (CustomException e) {map.put("type","error"); map.put("msg","原密码错误"); return map; }}else{map.put("type","error"); map.put("msg","两次密码不一致"); return map; }} /*** 查看个人信息* @param httpSession* @return*/@RequestMapping("inforEmployee.do")public @ResponseBody EmployeeCustomVo getInforEmployee(HttpSession httpSession){Integer id = (Integer) httpSession.getAttribute("employeeId"); EmployeeCustomVo employeeCustomVo = userInforService.getInforEmployee(id); return employeeCustomVo; } /*** 修改个人信息* @param httpSession* @param employee* @return*/@ResponseBody@RequestMapping("updateInforEmployee.do")public Message updateInforEmployee(HttpSession httpSession, Employee employee){Integer id = (Integer) httpSession.getAttribute("employeeId"); employee.seteId(id); if(userInforService.updateEmploueeById(id,employee)<=0) {return Message.error("修改信息失败"); }return Message.success(); } /*** 个人工资信息* @param pageNum* @param limit* @param year* @param httpSession* @return* @throws Exception*/@RequestMapping("employeeSalaryList.do")@ResponseBodypublic EmployeeSalaryVO findSelective(@RequestParam(value="https://www.it610.com/article/page", defaultValue="https://www.it610.com/article/1")int pageNum,@RequestParam(value="https://www.it610.com/article/limit", defaultValue="https://www.it610.com/article/10") int limit,@RequestParam(value="https://www.it610.com/article/year", defaultValue="https://www.it610.com/article/1") String year,HttpSession httpSession) throws Exception { Integer eId = (Integer) httpSession.getAttribute("employeeId"); //pageNum:起始页面pageSize:每页的大小PageHelper.startPage(pageNum,limit); //查找条件,一定要紧跟在startPage后List salaryList = userInforService.getEmployeeSalaryList(eId, year); PageInfo pageResult = new PageInfo(salaryList); //设置前台需要的数据EmployeeSalaryVO employeeSalaryVO = new EmployeeSalaryVO(); employeeSalaryVO.setCode(0); employeeSalaryVO.setMsg(""); employeeSalaryVO.setCount((int) pageResult.getTotal()); employeeSalaryVO.setData(pageResult.getList()); return employeeSalaryVO; } }
管理员和员工登陆控制
/** * @Author: admin * @Description: 管理员和员工登陆控制 **/@Controllerpublic class LoginController {@Autowiredprivate LoginServiceImpl loginService = null; /*** @Author: admin* @Description: 验证码变更* @Date: 14:33 2021/10/5* @Param: [request, response]* @Return: void**/@RequestMapping(value = "https://www.it610.com/changeCode.do")@ResponseBodypublic void getIdentifyingCode(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{// 验证码存储在session的identifyingCode,属性中CaptchaUtil.outputCaptcha(request, response); } // 获取员工登陆界面@RequestMapping("/")public String getLoginPage(){return "employee/login.html"; } // 获取管理员登陆界面@RequestMapping("/admin.do")public String getAdminLoginPage(HttpServletRequest request){String realPath = request.getServletContext().getRealPath("/"); request.getSession().setAttribute("realPath", realPath); return "admin/adminLogin.html"; }/*** 员工登录操作* @param model* @param httpSession* @param username* @param password* @param identifyingcode* @return*/@RequestMapping(value = "https://www.it610.com/employeeLogin.do")@ResponseBodypublic Message employeeLogin(HttpSession httpSession, String username,String password, String identifyingcode){if(StringUtils.isEmpty(username)) {return Message.error("请填写工号"); }if(StringUtils.isEmpty(password)) {return Message.error("请填写密码"); }if(StringUtils.isEmpty(identifyingcode)) {return Message.error("请填写验证码"); }String code = (String) httpSession.getAttribute("identifyingCode"); if(!identifyingcode.equalsIgnoreCase(code)){return Message.error("验证码错误"); }Employee employee = loginService.findEmployeeByIdAndPassword(username, password); if(employee==null) {return Message.error("工号或密码错误"); } httpSession.setAttribute("employeeId",employee.geteId()); return Message.success("员工登录成功"); } @RequestMapping(value = "https://www.it610.com/loginSuccess.do")public String loginSucceses(Model model) throws Exception{return "employee/index.html"; } /*** 管理员登录操作* @param model* @param httpSession* @param username* @param password* @param identifyingcode* @return*/@RequestMapping(value = "https://www.it610.com/adminLogin.do")@ResponseBodypublic Message adminLogin(HttpSession httpSession, String username,String password, String identifyingcode){if(StringUtils.isEmpty(username)) {return Message.error("请填写账号"); }if(StringUtils.isEmpty(password)) {return Message.error("请填写密码"); }if(StringUtils.isEmpty(identifyingcode)) {return Message.error("请填写验证码"); }String code = (String) httpSession.getAttribute("identifyingCode"); if(identifyingcode.equalsIgnoreCase(code)){SystemManager manager = loginService.findSystemManagerByIdAndPassword(username, password); if(manager==null) {return Message.error("账号或密码错误"); }// 保存到sessionhttpSession.setAttribute("admin",manager); return Message.success("登录成功"); }else {return Message.error("验证码错误"); }}@RequestMapping(value = "https://www.it610.com/getAdminAccount.do")@ResponseBodypublic String getAdminAccount(HttpSession httpSession){SystemManager systemManager = (SystemManager) httpSession.getAttribute("admin"); //SystemManager manager = loginService.findSystemManagerById(id); return systemManager.getSmAccount(); } @RequestMapping(value = "https://www.it610.com/getEmployeeAccount.do")@ResponseBodypublic Map getEmployeeAccount(HttpSession httpSession){Integer id = (Integer) httpSession.getAttribute("employeeId"); Employee employee = loginService.findEmployeeById(id); HashMap map = new HashMap(); map.put("account",employee.geteAccount()); map.put("name",employee.geteName()); return map; }@RequestMapping(value = "https://www.it610.com/logout.do")public String logout(HttpSession httpSession){httpSession.removeAttribute("employeeId"); return "redirect:/"; } @RequestMapping(value = "https://www.it610.com/logoutAdmin.do")public String logoutAdmin(HttpSession httpSession){httpSession.removeAttribute("admin"); return "redirect:/admin.do"; }}
用户管理操作
/** * 用户管理操作 */@Controller@RequestMapping("/user")public class UserController { @Autowiredprivate UserService userService; /*** 用户添加页面* @return*/@GetMapping("/add")public String create() {return "user/add"; } /*** 用户添加操作* @param user* @return*/@PostMapping("/add")@ResponseBodypublic Map 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}")@ResponseBodypublic Map 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")@ResponseBodypublic Map 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")@ResponseBodypublic Map 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")@ResponseBodypublic Map query(@RequestBody User user) {Listlist = userService.query(user); Integer count = userService.count(user); return MapControl.getInstance().success().page(list, count).getMap(); } //跳转列表页面@GetMapping("/list")public String list() {return "user/list"; } }
以上就是Java实战之火车票预订系统的实现的详细内容,更多关于Java火车票预订系统的资料请关注脚本之家其它相关文章!
推荐阅读
- Java基于虹软实现人脸识别、人脸比对、活性检测等
- 一文带你解读Spring5源码解析|一文带你解读Spring5源码解析 IOC之开启Bean的加载,以及FactoryBean和BeanFactory的区别。
- 如何写一份优秀的Java程序员简历
- iOS 自动化之atxserver
- 每日leetcode——两数之和
- Delphi|Delphi/C#之父首次访华(55岁了 每天都写代码)
- Delphi|60岁还在写代码的程序员大师,Delphi、C#、TypeScript之父Anders Hejlsberg(安德斯·海尔斯伯格)(编程符合10000小时定律)
- javascript|SegmentFault 创始人祁宁对话 C# 之父 Anders Hejlsberg
- javascript|Delphi、C#之父Anders Hejlsberg首次访华 推广TypeScript
- java编程创建型设计模式工厂方法模式示例详解