0


Java项目:火车票预订系统(java+JDBC+JSP+Servlet+html+mysql)

一、项目运行 环境配置:

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

项目技术:

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

个人中心Controller:

  1. /**
  2. * 个人中心Controller
  3. */
  4. @Controller
  5. public class UserInforController {
  6. @Autowired
  7. private UserInforServiceImpl userInforService = null;
  8. /**
  9. * 修改密码操作
  10. * @param oldPassword
  11. * @param newPassword
  12. * @param rePassword
  13. * @param httpSession
  14. * @return
  15. */
  16. @RequestMapping("changePassword.do")
  17. @ResponseBody
  18. public Map<String, String> changePassword(String oldPassword, String newPassword,
  19. String rePassword, HttpSession httpSession){
  20. HashMap<String, String> map = new HashMap<String, String>();
  21. if (newPassword.equals(rePassword)){
  22. SystemManager admin = (SystemManager) httpSession.getAttribute("admin");
  23. String encodeByMD5 = MD5Utils.encodeByMD5(oldPassword);
  24. if (encodeByMD5.equals(admin.getSmPassword())){
  25. String newPasswords = MD5Utils.encodeByMD5(newPassword);
  26. admin.setSmPassword(newPasswords);
  27. userInforService.updateSystemManagePassword(admin.getSmId(),admin);
  28. map.put("type","success");
  29. map.put("msg","密码修改成功");
  30. return map;
  31. }else{
  32. map.put("type","error");
  33. map.put("msg","原密码错误");
  34. return map;
  35. }
  36. }else{
  37. map.put("type","error");
  38. map.put("msg","两次密码不一致");
  39. return map;
  40. }
  41. }
  42. /**
  43. * 员工修改个人密码
  44. * @param oldPassword
  45. * @param newPassword
  46. * @param rePassword
  47. * @param httpSession
  48. * @return
  49. */
  50. @RequestMapping("changeEmployeePassword.do")
  51. @ResponseBody
  52. public Map<String, String> changeEmployeePassword(String oldPassword, String newPassword,
  53. String rePassword, HttpSession httpSession){
  54. HashMap<String, String> map = new HashMap<String, String>();
  55. if (newPassword.equals(rePassword)){
  56. Integer eid = (Integer) httpSession.getAttribute("employeeId");
  57. try {
  58. userInforService.updateEmployeePassword(eid, oldPassword, newPassword);
  59. map.put("type","success");
  60. map.put("msg","密码修改成功");
  61. return map;
  62. } catch (CustomException e) {
  63. map.put("type","error");
  64. map.put("msg","原密码错误");
  65. return map;
  66. }
  67. }else{
  68. map.put("type","error");
  69. map.put("msg","两次密码不一致");
  70. return map;
  71. }
  72. }
  73. /**
  74. * 查看个人信息
  75. * @param httpSession
  76. * @return
  77. */
  78. @RequestMapping("inforEmployee.do")
  79. public @ResponseBody EmployeeCustomVo getInforEmployee(HttpSession httpSession){
  80. Integer id = (Integer) httpSession.getAttribute("employeeId");
  81. EmployeeCustomVo employeeCustomVo = userInforService.getInforEmployee(id);
  82. return employeeCustomVo;
  83. }
  84. /**
  85. * 修改个人信息
  86. * @param httpSession
  87. * @param employee
  88. * @return
  89. */
  90. @ResponseBody
  91. @RequestMapping("updateInforEmployee.do")
  92. public Message updateInforEmployee(HttpSession httpSession, Employee employee){
  93. Integer id = (Integer) httpSession.getAttribute("employeeId");
  94. employee.seteId(id);
  95. if(userInforService.updateEmploueeById(id,employee)<=0) {
  96. return Message.error("修改信息失败");
  97. }
  98. return Message.success();
  99. }
  100. /**
  101. * 个人工资信息
  102. * @param pageNum
  103. * @param limit
  104. * @param year
  105. * @param httpSession
  106. * @return
  107. * @throws Exception
  108. */
  109. @RequestMapping("employeeSalaryList.do")
  110. @ResponseBody
  111. public EmployeeSalaryVO findSelective(
  112. @RequestParam(value="page", defaultValue="1")int pageNum,
  113. @RequestParam(value="limit", defaultValue="10") int limit,
  114. @RequestParam(value="year", defaultValue="1") String year,
  115. HttpSession httpSession) throws Exception {
  116. Integer eId = (Integer) httpSession.getAttribute("employeeId");
  117. //pageNum:起始页面 pageSize:每页的大小
  118. PageHelper.startPage(pageNum,limit);
  119. //查找条件,一定要紧跟在startPage后
  120. List<Salary> salaryList = userInforService.getEmployeeSalaryList(eId, year);
  121. PageInfo pageResult = new PageInfo(salaryList);
  122. //设置前台需要的数据
  123. EmployeeSalaryVO employeeSalaryVO = new EmployeeSalaryVO();
  124. employeeSalaryVO.setCode(0);
  125. employeeSalaryVO.setMsg("");
  126. employeeSalaryVO.setCount((int) pageResult.getTotal());
  127. employeeSalaryVO.setData(pageResult.getList());
  128. return employeeSalaryVO;
  129. }
  130. }

管理员和员工登陆控制:

  1. /**
  2. * @Author: admin
  3. * @Description: 管理员和员工登陆控制
  4. **/
  5. @Controller
  6. public class LoginController {
  7. @Autowired
  8. private LoginServiceImpl loginService = null;
  9. /**
  10. * @Author: admin
  11. * @Description: 验证码变更
  12. * @Date: 14:33 2021/10/5
  13. * @Param: [request, response]
  14. * @Return: void
  15. **/
  16. @RequestMapping(value = "/changeCode.do")
  17. @ResponseBody
  18. public void getIdentifyingCode(HttpServletRequest request, HttpServletResponse response)
  19. throws ServletException, IOException
  20. {
  21. // 验证码存储在session的identifyingCode,属性中
  22. CaptchaUtil.outputCaptcha(request, response);
  23. }
  24. // 获取员工登陆界面
  25. @RequestMapping("/")
  26. public String getLoginPage(){
  27. return "employee/login.html";
  28. }
  29. // 获取管理员登陆界面
  30. @RequestMapping("/admin.do")
  31. public String getAdminLoginPage(HttpServletRequest request){
  32. String realPath = request.getServletContext().getRealPath("/");
  33. request.getSession().setAttribute("realPath", realPath);
  34. return "admin/adminLogin.html";
  35. }
  36. /**
  37. * 员工登录操作
  38. * @param model
  39. * @param httpSession
  40. * @param username
  41. * @param password
  42. * @param identifyingcode
  43. * @return
  44. */
  45. @RequestMapping(value = "/employeeLogin.do")
  46. @ResponseBody
  47. public Message employeeLogin(HttpSession httpSession, String username,
  48. String password, String identifyingcode)
  49. {
  50. if(StringUtils.isEmpty(username)) {
  51. return Message.error("请填写工号");
  52. }
  53. if(StringUtils.isEmpty(password)) {
  54. return Message.error("请填写密码");
  55. }
  56. if(StringUtils.isEmpty(identifyingcode)) {
  57. return Message.error("请填写验证码");
  58. }
  59. String code = (String) httpSession.getAttribute("identifyingCode");
  60. if(!identifyingcode.equalsIgnoreCase(code)){
  61. return Message.error("验证码错误");
  62. }
  63. Employee employee = loginService.findEmployeeByIdAndPassword(username, password);
  64. if(employee==null) {
  65. return Message.error("工号或密码错误");
  66. }
  67. httpSession.setAttribute("employeeId",employee.geteId());
  68. return Message.success("员工登录成功");
  69. }
  70. @RequestMapping(value = "/loginSuccess.do")
  71. public String loginSucceses(Model model) throws Exception
  72. {
  73. return "employee/index.html";
  74. }
  75. /**
  76. * 管理员登录操作
  77. * @param model
  78. * @param httpSession
  79. * @param username
  80. * @param password
  81. * @param identifyingcode
  82. * @return
  83. */
  84. @RequestMapping(value = "/adminLogin.do")
  85. @ResponseBody
  86. public Message adminLogin(HttpSession httpSession, String username,
  87. String password, String identifyingcode)
  88. {
  89. if(StringUtils.isEmpty(username)) {
  90. return Message.error("请填写账号");
  91. }
  92. if(StringUtils.isEmpty(password)) {
  93. return Message.error("请填写密码");
  94. }
  95. if(StringUtils.isEmpty(identifyingcode)) {
  96. return Message.error("请填写验证码");
  97. }
  98. String code = (String) httpSession.getAttribute("identifyingCode");
  99. if(identifyingcode.equalsIgnoreCase(code)){
  100. SystemManager manager = loginService.findSystemManagerByIdAndPassword(username, password);
  101. if(manager==null) {
  102. return Message.error("账号或密码错误");
  103. }
  104. // 保存到session
  105. httpSession.setAttribute("admin",manager);
  106. return Message.success("登录成功");
  107. }else {
  108. return Message.error("验证码错误");
  109. }
  110. }
  111. @RequestMapping(value = "/getAdminAccount.do")
  112. @ResponseBody
  113. public String getAdminAccount(HttpSession httpSession){
  114. SystemManager systemManager = (SystemManager) httpSession.getAttribute("admin");
  115. // SystemManager manager = loginService.findSystemManagerById(id);
  116. return systemManager.getSmAccount();
  117. }
  118. @RequestMapping(value = "/getEmployeeAccount.do")
  119. @ResponseBody
  120. public Map<String,String> getEmployeeAccount(HttpSession httpSession){
  121. Integer id = (Integer) httpSession.getAttribute("employeeId");
  122. Employee employee = loginService.findEmployeeById(id);
  123. HashMap<String, String> map = new HashMap<String, String>();
  124. map.put("account",employee.geteAccount());
  125. map.put("name",employee.geteName());
  126. return map;
  127. }
  128. @RequestMapping(value = "/logout.do")
  129. public String logout(HttpSession httpSession){
  130. httpSession.removeAttribute("employeeId");
  131. return "redirect:/";
  132. }
  133. @RequestMapping(value = "/logoutAdmin.do")
  134. public String logoutAdmin(HttpSession httpSession){
  135. httpSession.removeAttribute("admin");
  136. return "redirect:/admin.do";
  137. }
  138. }

用户管理操作:

  1. /**
  2. * 用户管理操作
  3. */
  4. @Controller
  5. @RequestMapping("/user")
  6. public class UserController {
  7. @Autowired
  8. private UserService userService;
  9. /**
  10. * 用户添加页面
  11. * @return
  12. */
  13. @GetMapping("/add")
  14. public String create() {
  15. return "user/add";
  16. }
  17. /**
  18. * 用户添加操作
  19. * @param user
  20. * @return
  21. */
  22. @PostMapping("/add")
  23. @ResponseBody
  24. public Map<String, Object> add(@RequestBody User user) {
  25. if(StringUtils.isEmpty(user.getUserName())){
  26. return MapControl.getInstance().error("请填写用户名").getMap();
  27. }
  28. if(StringUtils.isEmpty(user.getName())){
  29. return MapControl.getInstance().error("请填写名称").getMap();
  30. }
  31. if(StringUtils.isEmpty(user.getUserPwd())){
  32. return MapControl.getInstance().error("请填写密码").getMap();
  33. }
  34. int result = userService.create(user);
  35. if (result <= 0) {
  36. return MapControl.getInstance().error().getMap();
  37. }
  38. return MapControl.getInstance().success().getMap();
  39. }
  40. /**
  41. * 根据id删除
  42. * @param id
  43. * @return
  44. */
  45. @PostMapping("/delete/{id}")
  46. @ResponseBody
  47. public Map<String, Object> delete(@PathVariable("id") Integer id) {
  48. int result = userService.delete(id);
  49. if (result <= 0) {
  50. return MapControl.getInstance().error().getMap();
  51. }
  52. return MapControl.getInstance().success().getMap();
  53. }
  54. //批量删除
  55. @PostMapping("/delete")
  56. @ResponseBody
  57. public Map<String, Object> delete(String ids) {
  58. int result = userService.delete(ids);
  59. if (result <= 0) {
  60. return MapControl.getInstance().error().getMap();
  61. }
  62. return MapControl.getInstance().success().getMap();
  63. }
  64. /**
  65. * 编辑用户信息操作
  66. * @param user
  67. * @return
  68. */
  69. @PostMapping("/edit")
  70. @ResponseBody
  71. public Map<String, Object> edit(@RequestBody User user) {
  72. if(StringUtils.isEmpty(user.getUserName())){
  73. return MapControl.getInstance().error("请填写用户名").getMap();
  74. }
  75. if(StringUtils.isEmpty(user.getName())){
  76. return MapControl.getInstance().error("请填写名称").getMap();
  77. }
  78. if(StringUtils.isEmpty(user.getUserPwd())){
  79. return MapControl.getInstance().error("请填写密码").getMap();
  80. }
  81. int result = userService.update(user);
  82. if (result <= 0) {
  83. return MapControl.getInstance().error().getMap();
  84. }
  85. return MapControl.getInstance().success().getMap();
  86. }
  87. /**
  88. * 根据id查询,跳转修改页面
  89. * @param id
  90. * @param modelMap
  91. * @return
  92. */
  93. @GetMapping("/edit/{id}")
  94. public String edit(@PathVariable("id") Integer id, ModelMap modelMap) {
  95. User user = userService.detail(id);
  96. modelMap.addAttribute("user", user);
  97. return "user/edit";
  98. }
  99. //查询所有
  100. @PostMapping("/query")
  101. @ResponseBody
  102. public Map<String, Object> query(@RequestBody User user) {
  103. List<User> list = userService.query(user);
  104. Integer count = userService.count(user);
  105. return MapControl.getInstance().success().page(list, count).getMap();
  106. }
  107. //跳转列表页面
  108. @GetMapping("/list")
  109. public String list() {
  110. return "user/list";
  111. }
  112. }
标签: mysql java html

本文转载自: https://blog.csdn.net/pastclouds/article/details/123042822
版权归原作者 OldWinePot 所有, 如有侵权,请联系我们删除。

“Java项目:火车票预订系统(java+JDBC+JSP+Servlet+html+mysql)”的评论:

还没有评论