当前位置:   article > 正文

Java项目:景点门票预订管理系统(java+SSM+JSP+bootstrap+Mysql)_【java+jsp+mysql】订票系统

【java+jsp+mysql】订票系统

源码获取:俺的博客首页 "资源" 里下载!

项目介绍

本项目包含管理员与用户两种角色;
管理员角色包含以下功能:管理员登录,用户管理,景点管理,景点信息管理,资讯信息管理,酒店信息管理,旅游线路管理等功能。
用户角色包含以下功能:用户登录,查看我的订单,查看景点详情,提交订单等功能

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 
5.数据库:MySql 5.7版本;

技术栈

1. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+bootstrap+jQuery

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/

 

 

 

 

 

用户管理控制层: 

  1. @Controller
  2. @RequestMapping("/user.do")
  3. public class UserController {
  4. @Autowired
  5. private UserService userService;
  6. @Autowired
  7. private TouristService touristService;
  8. @Autowired
  9. private OrdersService ordersService;
  10. @RequestMapping(params="method=getAllUser")
  11. public ModelAndView getAllUser(HttpServletRequest request,HttpServletResponse reponse){
  12. ModelAndView mav = new ModelAndView();
  13. mav.setViewName("admin/allUser");
  14. return mav;
  15. }
  16. @RequestMapping(params="method=checkAllUser")
  17. public ModelAndView checkAllUser(HttpServletRequest request,HttpServletResponse reponse){
  18. ModelAndView mav = new ModelAndView();
  19. mav.setViewName("admin/checkUserList");
  20. return mav;
  21. }
  22. @RequestMapping(params="method=getCheckUserData")
  23. public ModelAndView getCheckUserData(HttpServletRequest request,HttpServletResponse response,@ModelAttribute User user){
  24. List<User> findAll = new ArrayList<User>();
  25. JSONObject obj = new JSONObject();
  26. try{
  27. if(user.getUsername()!=null&&StringUtils.isBlank(user.getUsername())){
  28. user.setUsername(null);
  29. }
  30. user.setState(0);
  31. findAll = userService.findAll(user);
  32. }
  33. catch(Exception e){
  34. }
  35. obj.put("rows", findAll);
  36. obj.put("total", findAll.size());
  37. return CommonResponse.JsonAjax(obj.toString());
  38. }
  39. @RequestMapping(params="method=getUserData")
  40. public ModelAndView getUserData(HttpServletRequest request,HttpServletResponse response,@ModelAttribute User user){
  41. List<User> findAll = new ArrayList<User>();
  42. JSONObject obj = new JSONObject();
  43. try{
  44. if(user.getUsername()!=null&&StringUtils.isBlank(user.getUsername())){
  45. user.setUsername(null);
  46. }
  47. user.setState(1);
  48. findAll = userService.findAll(user);
  49. obj.put("rows", findAll);
  50. obj.put("total", findAll.size());
  51. }
  52. catch(Exception e){
  53. obj.put("rows", findAll);
  54. obj.put("total", findAll.size());
  55. }
  56. return CommonResponse.JsonAjax(obj.toString());
  57. }
  58. @RequestMapping(params="method=addUser")
  59. public ModelAndView addUser(HttpServletRequest request,HttpServletResponse response,@ModelAttribute User user){
  60. response.setContentType("text/html;charset=utf-8");
  61. JSONObject obj = new JSONObject();
  62. user.setRole(0);
  63. user.setState(0);
  64. try{
  65. userService.save(user);
  66. obj.put("statusCode", 200);
  67. obj.put("title", "操作提示");
  68. obj.put("message", "恭喜你,操作成功");
  69. }
  70. catch(Exception e){
  71. obj.put("statusCode", 201);
  72. obj.put("title", "操作提示");
  73. obj.put("message", "添加用户失败");
  74. }
  75. return CommonResponse.JsonAjax(obj.toString());
  76. }
  77. @RequestMapping(params="method=toAddUser")
  78. public ModelAndView toAddUser(HttpServletRequest request,HttpServletResponse response){
  79. ModelAndView mav = new ModelAndView();
  80. mav.setViewName("admin/userAdd");
  81. return mav;
  82. }
  83. @RequestMapping(params="method=toEditUser")
  84. public ModelAndView toEditUser(HttpServletRequest request,HttpServletResponse response){
  85. ModelAndView mav = new ModelAndView();
  86. mav.setViewName("admin/userEdit");
  87. return mav;
  88. }
  89. @RequestMapping(params="method=toCheckUser")
  90. public ModelAndView toCheckUser(HttpServletRequest request,HttpServletResponse response){
  91. ModelAndView mav = new ModelAndView();
  92. mav.setViewName("admin/userCheck");
  93. return mav;
  94. }
  95. @RequestMapping(params="method=getUser")
  96. public ModelAndView getUser(HttpServletRequest request,HttpServletResponse response){
  97. ModelAndView mav = new ModelAndView();
  98. mav.setViewName("editUser");
  99. return mav;
  100. }
  101. @RequestMapping(params="method=findUser")
  102. public ModelAndView findUser(HttpServletRequest request,HttpServletResponse response){
  103. int id =Integer.valueOf(request.getParameter("id"));
  104. User user = userService.findById(id);
  105. return CommonResponse.JsonAjax(JSONObject.fromObject(user).toString());
  106. }
  107. @RequestMapping(params="method=delUser")
  108. public ModelAndView delUser(HttpServletRequest request,HttpServletResponse response){
  109. JSONObject obj = new JSONObject();
  110. try{
  111. int id=Integer.valueOf(String.valueOf(request.getParameter("id")));
  112. if(userService.delete(id)){
  113. obj.put("statusCode", 200);
  114. obj.put("title", "操作提示");
  115. obj.put("message", "恭喜你,操作成功");
  116. }
  117. else{
  118. obj.put("statusCode", 201);
  119. obj.put("title", "操作提示");
  120. obj.put("message", "删除用户失败");
  121. }
  122. }
  123. catch(Exception e){
  124. obj.put("statusCode", 201);
  125. obj.put("title", "操作提示");
  126. obj.put("message", "删除用户失败");
  127. }
  128. return CommonResponse.JsonAjax(obj.toString());
  129. }
  130. @RequestMapping(params="method=updateUser")
  131. public ModelAndView updateUser(User user,HttpServletRequest request){
  132. JSONObject obj = new JSONObject();
  133. try{
  134. if(userService.update(user)){
  135. user = userService.findById(user.getId());
  136. obj.put("statusCode", 200);
  137. obj.put("title", "操作提示");
  138. obj.put("message", "恭喜你,操作成功");
  139. }else{
  140. obj.put("statusCode", 201);
  141. obj.put("title", "操作提示");
  142. obj.put("message", "添加用户失败");
  143. }
  144. }
  145. catch(Exception ex){
  146. obj.put("statusCode", 201);
  147. obj.put("title", "操作提示");
  148. obj.put("message", "添加用户失败");
  149. }
  150. return CommonResponse.JsonAjax(obj.toString());
  151. }
  152. @RequestMapping(params="method=updateCheckUser")
  153. public ModelAndView updateCheckUser(User user,HttpServletRequest request){
  154. JSONObject obj = new JSONObject();
  155. try{
  156. user.setState(1);
  157. if(userService.update(user)){
  158. user = userService.findById(user.getId());
  159. request.setAttribute("user", user);
  160. obj.put("statusCode", 200);
  161. obj.put("title", "操作提示");
  162. obj.put("message", "恭喜你,操作成功");
  163. }else{
  164. obj.put("statusCode", 201);
  165. obj.put("title", "操作提示");
  166. obj.put("message", "添加用户失败");
  167. }
  168. }
  169. catch(Exception ex){
  170. obj.put("statusCode", 201);
  171. obj.put("title", "操作提示");
  172. obj.put("message", "添加用户失败");
  173. }
  174. return CommonResponse.JsonAjax(obj.toString());
  175. }
  176. @RequestMapping(params="method=buyTicket")
  177. public ModelAndView buyTicket(int id, String date, HttpServletRequest request){
  178. JSONObject obj = new JSONObject();
  179. User user = (User) request.getSession().getAttribute("user");
  180. if (user == null) {
  181. obj.put("statusCode", 201);
  182. obj.put("title", "操作提示");
  183. obj.put("message", "请先登录!");
  184. return CommonResponse.JsonAjax(obj.toString());
  185. }
  186. Tourist con = new Tourist();
  187. con.setId(id);
  188. Tourist tourist = touristService.findTourist(con);
  189. Orders order = new Orders();
  190. order.setCreatetime(DateUtil.parseDateTimeToString(new Date()));
  191. order.setPrice(tourist.getPrice());
  192. order.setTouristid(id);
  193. order.setTouristname(tourist.getName());
  194. order.setUserid(user.getId());
  195. order.setUsername(user.getUsername());
  196. order.setStatus("未付款");
  197. order.setTicketdate(date);
  198. try{
  199. ordersService.save(order);
  200. obj.put("statusCode", 200);
  201. obj.put("title", "操作提示");
  202. obj.put("message", "下单成功");
  203. }
  204. catch(Exception ex){
  205. obj.put("statusCode", 201);
  206. obj.put("title", "操作提示");
  207. obj.put("message", "下单失败");
  208. }
  209. return CommonResponse.JsonAjax(obj.toString());
  210. }
  211. @RequestMapping(params="method=payOrder")
  212. public ModelAndView payOrder(int id,HttpServletRequest request){
  213. JSONObject obj = new JSONObject();
  214. Orders order = ordersService.findById(id);
  215. order.setStatus("已付款");
  216. try{
  217. ordersService.update(order);
  218. obj.put("statusCode", 200);
  219. obj.put("title", "操作提示");
  220. obj.put("message", "付款成功");
  221. }
  222. catch(Exception ex){
  223. obj.put("statusCode", 201);
  224. obj.put("title", "操作提示");
  225. obj.put("message", "付款失败");
  226. }
  227. return CommonResponse.JsonAjax(obj.toString());
  228. }
  229. }

登录管理控制层:

  1. @Controller
  2. @RequestMapping("/login.do")
  3. public class LoginController {
  4. @Autowired
  5. private UserService userService;
  6. @RequestMapping(params="method=Index")
  7. public ModelAndView Index(HttpServletRequest request,HttpServletResponse response){
  8. ModelAndView mav = new ModelAndView();
  9. User user = (User)request.getSession().getAttribute("user");
  10. if(user!=null){
  11. if(user.getRole()==1&&user.getState()==1){
  12. mav.setViewName("admin/index");
  13. mav.addObject("user", user);
  14. }
  15. else{
  16. mav.setViewName("redirect:home.do?method=homeIndex");
  17. if(user.getState()==1){
  18. mav.addObject("user",user);
  19. }
  20. }
  21. }
  22. else{
  23. mav.setViewName("redirect:login.do?method=Login");
  24. }
  25. return mav;
  26. }
  27. @RequestMapping(params="method=Login")
  28. public ModelAndView Login(HttpServletRequest request,HttpServletResponse response){
  29. ModelAndView mav = new ModelAndView();
  30. User user = (User)request.getSession().getAttribute("user");
  31. if(user!=null){
  32. mav.setViewName("redirect:login.do?method=Index");
  33. }
  34. else{
  35. mav.setViewName("admin/login");
  36. }
  37. return mav;
  38. }
  39. @RequestMapping(params="method=checkLogin")
  40. private ModelAndView checkLogin(HttpServletRequest request,HttpServletResponse response){
  41. String username=request.getParameter("username");
  42. String password=request.getParameter("password");
  43. JSONObject obj = new JSONObject();
  44. HttpSession session = request.getSession();
  45. try{
  46. User user = this.userService.findByUsername(username);
  47. if(user!=null){
  48. if(user.getPassword().equals(password)){
  49. obj.put("code", 1);
  50. obj.put("referer", "login.do?method=Index");
  51. session.setAttribute("user", user);
  52. }
  53. else{
  54. obj.put("code", -1);
  55. }
  56. }
  57. else{
  58. obj.put("code", -1);
  59. }
  60. }
  61. catch(Exception e){
  62. obj.put("code", -1);
  63. }
  64. return CommonResponse.JsonAjax(obj.toString());
  65. }
  66. @RequestMapping(params="method=Loginout")
  67. public ModelAndView Loginout(HttpServletRequest request,HttpServletResponse response){
  68. HttpSession session = request.getSession();
  69. session.removeAttribute("user");
  70. ModelAndView mav = new ModelAndView();
  71. mav.setViewName("redirect:login.do?method=Login");
  72. return mav;
  73. }
  74. }

酒店管理控制层:

  1. @Controller
  2. @RequestMapping("/hotel.do")
  3. public class HotelController {
  4. @Autowired
  5. private HotelService hotelService;
  6. @RequestMapping(params="method=touristMain")
  7. public ModelAndView touristMain(HttpServletRequest request,HttpServletResponse response){
  8. ModelAndView mav = new ModelAndView();
  9. mav.setViewName("admin/hotelMain");
  10. return mav;
  11. }
  12. @RequestMapping(params="method=touristMainData")
  13. public ModelAndView touristMainData(HttpServletRequest request,HttpServletResponse response,@ModelAttribute Hotel tourist){
  14. response.setContentType("text/html;charset=utf-8");
  15. List<Hotel> list = new ArrayList<Hotel>();
  16. JSONObject obj = new JSONObject();
  17. try{
  18. if(StringUtils.isBlank(tourist.getName())){
  19. tourist.setName(null);
  20. }
  21. list=this.hotelService.findHotelList(tourist);
  22. }
  23. catch(Exception e){
  24. }
  25. obj.put("rows", list);
  26. obj.put("total", list.size());
  27. return CommonResponse.JsonAjax(obj.toString());
  28. }
  29. @RequestMapping(params="method=toAddTourist")
  30. public ModelAndView toAddTourist(HttpServletRequest request,HttpServletResponse response){
  31. ModelAndView mav = new ModelAndView();
  32. mav.setViewName("admin/hotelAdd");
  33. return mav;
  34. }
  35. @RequestMapping(params="method=addTourist")
  36. public ModelAndView addTourist(HttpServletRequest request,HttpServletResponse response,@ModelAttribute Hotel tourist){
  37. response.setContentType("text/html;charset=utf-8");
  38. JSONObject obj = new JSONObject();
  39. try{
  40. this.hotelService.save(tourist);
  41. obj.put("statusCode", 200);
  42. obj.put("title", "操作提示");
  43. obj.put("message", "恭喜你,添加酒店成功");
  44. }
  45. catch(Exception ex){
  46. obj.put("statusCode", 201);
  47. obj.put("title", "操作提示");
  48. obj.put("message", "添加酒店失败");
  49. }
  50. return CommonResponse.JsonAjax(obj.toString());
  51. }
  52. @RequestMapping(params="method=toEditTourist")
  53. public ModelAndView toEditTourist(HttpServletRequest request,HttpServletResponse response){
  54. ModelAndView mav = new ModelAndView();
  55. mav.setViewName("admin/hotelEdit");
  56. return mav;
  57. }
  58. @RequestMapping(params="method=findTourist")
  59. public ModelAndView findTourist(HttpServletRequest request,HttpServletResponse response){
  60. response.setContentType("text/html;charset=utf-8");
  61. Hotel tourist = new Hotel();
  62. try{
  63. int id =Integer.valueOf(request.getParameter("id"));
  64. Hotel bean = new Hotel();
  65. bean.setId(id);
  66. tourist=this.hotelService.findHotelinfo(bean);
  67. }
  68. catch(Exception ex){
  69. }
  70. return CommonResponse.JsonAjax(JSONObject.fromObject(tourist).toString());
  71. }
  72. @RequestMapping(params="method=updateTourist")
  73. public ModelAndView updateTourist(HttpServletRequest request,HttpServletResponse response,@ModelAttribute Hotel tourist){
  74. response.setContentType("text/html;charset=utf-8");
  75. JSONObject obj = new JSONObject();
  76. try{
  77. if(this.hotelService.update(tourist)){
  78. obj.put("statusCode", 200);
  79. obj.put("title", "操作提示");
  80. obj.put("message", "恭喜你,操作成功");
  81. }
  82. else{
  83. obj.put("statusCode", 201);
  84. obj.put("title", "操作提示");
  85. obj.put("message", "更新酒店失败");
  86. }
  87. }
  88. catch(Exception ex){
  89. obj.put("statusCode", 201);
  90. obj.put("title", "操作提示");
  91. obj.put("message", "更新酒店失败");
  92. }
  93. return CommonResponse.JsonAjax(obj.toString());
  94. }
  95. @RequestMapping(params="method=deleteTourist")
  96. public ModelAndView deleteTourist(HttpServletRequest request,HttpServletResponse response,@ModelAttribute Hotel tourist){
  97. response.setContentType("text/html;charset=utf-8");
  98. JSONObject obj = new JSONObject();
  99. try{
  100. if(this.hotelService.delete(tourist)){
  101. obj.put("statusCode", 200);
  102. obj.put("title", "操作提示");
  103. obj.put("message", "恭喜你,操作成功");
  104. }
  105. else{
  106. obj.put("statusCode", 201);
  107. obj.put("title", "操作提示");
  108. obj.put("message", "删除酒店失败");
  109. }
  110. }
  111. catch(Exception ex){
  112. obj.put("statusCode", 201);
  113. obj.put("title", "操作提示");
  114. obj.put("message", "删除酒店失败");
  115. }
  116. return CommonResponse.JsonAjax(obj.toString());
  117. }
  118. @RequestMapping(params = "method=fileUpLoad")
  119. //btnFile对应页面的name属性
  120. public ModelAndView fileUpLoad(MultipartFile file, HttpServletRequest request, HttpServletResponse response){
  121. response.setContentType("text/html;charset=utf-8");
  122. JSONObject obj = new JSONObject();
  123. try{
  124. String path = request.getSession().getServletContext().getRealPath("uploads");
  125. //上传文件名
  126. String filename = new Date().getTime()+"_"+file.getOriginalFilename();
  127. File filepath = new File(path,filename);
  128. //判断路径是否存在,如果不存在就创建一个
  129. if (!filepath.getParentFile().exists()) {
  130. filepath.getParentFile().mkdirs();
  131. }
  132. //将上传文件保存到一个目标文件当中
  133. file.transferTo(new File(path + File.separator + filename));
  134. obj.put("statusCode", 200);
  135. obj.put("title", "操作提示");
  136. obj.put("message", "上传文件成功");
  137. obj.put("filePath", filename);
  138. // OutputUtil.jsonOutPut(response, null);
  139. }catch (Exception e) {
  140. // OutputUtil.errorOutPut(response, "系统异常");
  141. obj.put("statusCode", 201);
  142. obj.put("title", "操作提示");
  143. obj.put("message", "上传文件失败");
  144. }
  145. return CommonResponse.JsonAjax(obj.toString());
  146. }
  147. }

源码获取:俺的博客首页 "资源" 里下载!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/213124
推荐阅读
相关标签
  

闽ICP备14008679号