当前位置:   article > 正文

Java项目:网上订餐管理系统(java+JSP+bootstrap+jQuery+Mysql)_jsp+servlet+jdbc+mysql项目点餐网站项目源码

jsp+servlet+jdbc+mysql项目点餐网站项目源码

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

项目介绍

基于JSP+Servlet的网上订餐管理系统的设计与实现。该项目为前后台管理项目。
前台主要展示给普通用户,主要功能有菜品分类、最新菜品、销售排行、美食预订、营养小贴士、餐点搜索、订餐车、
在线留言等;

后台主要提供给管理员,主要功能有菜品管理、菜品类别管理、营养小贴士管理、会员管理、员工管理、留言管理、采购管理、销售订单查询、统计管理、用户管理等;


环境需要

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.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 
6.数据库:MySql 5.7版本;


技术栈

1. 后端:Servlet
2. 前端:JSP+bootstrap+jQuery

使用说明

1. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需jar包;
2. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
3. 将项目中DBConn.java文件中的数据库配置改为自己的配置
4. 配置tomcat,然后运行项目,输入localhost:8080/xxx 登录
5. 后台管理员账户:admin 密码:admin
前台普通用户:111 密码:111


 

 

 

 

 

 

用户管理控制层:

  1. @Controller
  2. public class TbUserController {
  3. @Resource
  4. TbUserServiceImpl tbUserService;
  5. @GetMapping("/toLogin")
  6. public String toLogin(){
  7. return "user/login";
  8. }
  9. @PostMapping("/register")
  10. public String register(String uUsername, String uPassword, String uRole,Model model){
  11. List<TbUser> users = tbUserService.selectAllUser();
  12. for (TbUser temp : users){ //验证成功,直接登录
  13. if(uUsername.equals(temp.getUUsername())){
  14. model.addAttribute("msg","刚刚:注册失败,该用户已存在!");
  15. return "user/login";
  16. }
  17. }
  18. TbUser user = new TbUser();
  19. user.setUUsername(uUsername);
  20. user.setUPassword(uPassword);
  21. user.setURole(uRole);
  22. tbUserService.insertUser(user);
  23. model.addAttribute("msg","刚刚:注册成功,赶快登录进行登录吧~");
  24. return "user/login";
  25. }
  26. /*插入用户数据,返回字符串信息*/
  27. @ResponseBody
  28. @RequestMapping("/insertUserInfo")
  29. public String insertUserInfo(String uUsername, String uPassword, String uRole){
  30. //查询是否存在用户名了
  31. String msg = "未知错误!";
  32. List<TbUser> users = tbUserService.selectUserByName(uUsername);
  33. if(users.size() == 0){
  34. TbUser user = new TbUser();
  35. user.setUUsername(uUsername);
  36. user.setUPassword(uPassword);
  37. user.setURole(uRole); //字符串转化为int
  38. int i = tbUserService.insertUser(user);
  39. if(i != 0){
  40. msg = "新添用户成功!";
  41. }
  42. }else {
  43. msg = "该用户名已存在,插入失败!";
  44. }
  45. return msg;
  46. }
  47. /*编辑用户信息,返回字符串信息*/
  48. @ResponseBody
  49. @RequestMapping("/edUserInfo")
  50. public String edUserInfo(TbUser user){
  51. tbUserService.updateUserByUser(user);
  52. return "用户数据已更新!";
  53. }
  54. /*跳转用户信息页面 + 分页*/
  55. @RequestMapping("/userInfo") //1开始
  56. public String userInfo(Model model,@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum){
  57. List<TbUser> users = tbUserService.selectAllUser();
  58. Page<TbUser> page = new Page<>(pageNum,5);
  59. tbUserService.selectPage(page);
  60. model.addAttribute("users",users);
  61. model.addAttribute("page",page);
  62. return "user/userInfo";
  63. }
  64. /*删除用户*/
  65. @RequestMapping("/deleteUser/{uId}")
  66. public String deleteUser(@PathVariable("uId")int uId, Model model){
  67. tbUserService.deleteUserById(uId);
  68. model.addAttribute("msg","删除成功!");
  69. return "redirect:/userInfo";
  70. }
  71. @GetMapping("/myInfo")
  72. public String myInfo(Principal principal,Model model){
  73. String str = principal.getName();
  74. List<TbUser> list = tbUserService.selectAllUser();
  75. for(TbUser tbUser:list) {
  76. if(tbUser.getUUsername().equals(str)){
  77. model.addAttribute("Member",tbUser.getMember());
  78. }
  79. }
  80. return "user/myInfo";
  81. }
  82. /*上传头像*/
  83. @RequestMapping("/updateMyImg")
  84. public String updateMyImg(@RequestParam(value = "updateHeadImg") MultipartFile updateHeadImg,
  85. int uId, Model model, HttpSession session){
  86. String imgPath = FileUpload.uploadFile(updateHeadImg);
  87. //更新操作
  88. TbUser user = tbUserService.selectUserById(uId);
  89. user.setUUrl(imgPath);
  90. tbUserService.updateUserByUser(user);
  91. user = tbUserService.selectUserById(uId);
  92. UpdateSession.reloadUserAuthority(session,user);
  93. return "redirect:/myInfo";
  94. }
  95. /*更新我的信息*/
  96. @RequestMapping("/updateMyInfo")
  97. public String updateMyInfo(TbUser user, HttpSession session){
  98. //更新操作
  99. TbUser tbUser = tbUserService.selectUserById(user.getUId()); //保存新数据,避免被原数据覆盖
  100. System.out.println("tbUser = " + tbUser);
  101. user.setUUsername(tbUser.getUUsername());
  102. user.setUPassword(tbUser.getPassword());
  103. user.setUMoney(tbUser.getUMoney());
  104. tbUserService.updateUserByUser(user);
  105. user = tbUserService.selectUserById(user.getUId());
  106. UpdateSession.reloadUserAuthority(session,user);
  107. return "redirect:/myInfo";
  108. }
  109. @RequestMapping("/shenqinghuiyuan")
  110. public String shenqinghuiyuan(Integer uId, HttpSession session,Model model){
  111. //更新操作
  112. //保存新数据,避免被原数据覆盖
  113. TbUser tbUser = tbUserService.selectUserById(uId);
  114. if(tbUser.getUMoney()>200){
  115. tbUserService.updateMeber(uId);
  116. model.addAttribute("Member",2);
  117. model.addAttribute("error","申请成功,请重新登录后方可生效");
  118. }else{
  119. model.addAttribute("error","未满足条件");
  120. model.addAttribute("Member",1);
  121. }
  122. return "user/myInfo";
  123. }
  124. // @GetMapping("/outLogin")
  125. // public String outLogin(HttpSession session){
  126. // session.removeAttribute("user");
  127. // return "user/login";
  128. // }
  129. // @PostMapping("/login") 添加了安全策略不在需要手动验证,只需要提供个请求路径
  130. // public void login(String uUsername, String uPassword, Model model, HttpSession session){
  131. // List<TbUser> users = tbUserService.selectAllUser();
  132. // for (TbUser temp : users){ //验证成功,直接登录
  133. // if(uUsername.equals(temp.getUUsername()) && uPassword.equals(temp.getUPassword())){
  134. // session.setAttribute("user",temp);
  135. // return "redirect:/";
  136. // }
  137. // if(uUsername.equals(temp.getUUsername()) && !uPassword.equals(temp.getUPassword())){
  138. // model.addAttribute("msg","刚刚:密码错误,登录失败!");
  139. // return "user/login";
  140. // }
  141. // }
  142. // model.addAttribute("msg","刚刚:该用户不存在,请重新输入!");
  143. // return "user/login";
  144. // }
  145. }

订单详情管理控制层: 

  1. @Controller
  2. public class OrderDetailController {
  3. @Resource
  4. OrderDetailServiceImpl orderDetailService;
  5. @Resource
  6. ShoppingCartServiceImpl shoppingCartService;
  7. @Resource
  8. MenuDetailServiceImpl menuDetailService;
  9. @Resource
  10. TbUserServiceImpl tbUserService;
  11. //修改订单状态,从01,由商家更新
  12. @ResponseBody
  13. @RequestMapping("/changeStatusToOne")
  14. public String changeStatusToOne(int odId){
  15. OrderDetail one = orderDetailService.selectOneByOdId(odId);
  16. one.setOdStatus(1);
  17. orderDetailService.updateOrder(one); //更新订单
  18. return "已接单,尽快送餐吧~";
  19. }
  20. //修改订单状态,从12,由用户更新
  21. @ResponseBody
  22. @RequestMapping("/changeStatusToTwo")
  23. public String changeStatusToTwo(int odId){
  24. OrderDetail one = orderDetailService.selectOneByOdId(odId);
  25. one.setOdStatus(2);
  26. orderDetailService.updateOrder(one); //更新订单
  27. //同时更新商家的账户
  28. TbUser adminUser = tbUserService.selectUserById(1);
  29. int updateMoney = one.getOdTotal()+adminUser.getUMoney();
  30. adminUser.setUMoney(updateMoney);
  31. tbUserService.updateUserByUser(adminUser);
  32. return "您已确认送达,钱已入商家商户,订单已完结~";
  33. }
  34. @RequestMapping("/orderManage")
  35. public String orderManage(Model model,@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum){
  36. List<OrderDetail> orders = orderDetailService.selectAll();
  37. Collections.reverse(orders); //倒叙
  38. Page<TbUser> page = new Page<>(pageNum,10);
  39. orderDetailService.selectPage(page); //分页
  40. int allCount = orders.size(); //总数
  41. int pendingCount = 0; //待处理单数
  42. int receivedCount = 0; //待已接单数
  43. int finishCount = 0; //已完结
  44. for (OrderDetail order : orders){
  45. if(order.getOdStatus() == 0){
  46. pendingCount += 1;
  47. }else if(order.getOdStatus() == 1){
  48. receivedCount += 1;
  49. }else{
  50. finishCount += 1;
  51. }
  52. }
  53. TbUser adminUser = tbUserService.selectUserById(1);
  54. model.addAttribute("total",adminUser.getUMoney());
  55. model.addAttribute("page",page);
  56. model.addAttribute("orders",orders);
  57. model.addAttribute("allCount",allCount);
  58. model.addAttribute("pendingCount",pendingCount);
  59. model.addAttribute("receivedCount",receivedCount);
  60. model.addAttribute("finishCount",finishCount);
  61. return "menu/orderManage";
  62. }
  63. @RequestMapping("/myOrder")
  64. public String myOrder(Model model,int uId){
  65. List<OrderDetail> myOrders = orderDetailService.selectAllOrderByUId(uId);
  66. TbUser user = tbUserService.selectUserById(uId);
  67. model.addAttribute("myOrders",myOrders);
  68. model.addAttribute("total",user.getUMoney());
  69. return "user/myOrder";
  70. }
  71. @ResponseBody
  72. @PostMapping("/toOrder")
  73. public String toOrder(OrderDetail orderDetail){
  74. TbUser user = tbUserService.selectUserById(orderDetail.getUId());
  75. //查询当前用户的所以购物车
  76. List<ShoppingCart> carts = shoppingCartService.selectAllByUId(orderDetail.getUId());
  77. //获取到具体商品
  78. String odDetail = "【";
  79. int odTotal = 0;
  80. for (ShoppingCart cart : carts){
  81. odDetail += cart.getScName()+" × "+cart.getScAmount()+";"; //拼接成:米饭 × 1;格式
  82. odTotal += cart.getScPrice()*cart.getScAmount(); //数量×价格
  83. }
  84. odDetail += "】";
  85. //赋值
  86. orderDetail.setOdDetail(odDetail);
  87. if(user.getMember()==2){
  88. orderDetail.setOdTotal((int)(odTotal * 0.88));
  89. }else{
  90. orderDetail.setOdTotal(odTotal);
  91. }
  92. orderDetail.setOdStatus(0);
  93. orderDetail.setOdNo(RandomNo.getRandomNo());
  94. //完成插入
  95. orderDetailService.insertOrder(orderDetail);
  96. //清空购物车 + 更新商品数据
  97. for (ShoppingCart cart : carts){
  98. shoppingCartService.deleteById(cart.getScId()); //删除购物车数据
  99. MenuDetail menuDetail = menuDetailService.selectById(cart.getMdId()); //通过产品id获得产品
  100. menuDetail.setMdAmount(menuDetail.getMdAmount()-cart.getScAmount()); //减去下单数量
  101. menuDetailService.updateMenu(menuDetail); //更新产品数据
  102. }
  103. TbUser User= tbUserService.selectUserById(orderDetail.getUId()); //用户更新支付金额
  104. System.out.println(odTotal+"=============");
  105. System.out.println(user.getMember()+"====="+odTotal);
  106. if(user.getMember()==1 && odTotal>200) {//当会员为1时,说明不是会员,并且支付的金额大于200
  107. user.setMember(2);
  108. System.out.println("进入方法后"+user.getMember());
  109. }
  110. user.setUMoney(user.getUMoney()+odTotal);
  111. System.out.println(user.getMember());
  112. tbUserService.updateUserByUser(user);
  113. List<OrderDetail> details = orderDetailService.selectAllOrderByUId(orderDetail.getUId());
  114. for (OrderDetail detail : details){
  115. System.out.println("detail = " + detail.getOdCreateTime());
  116. }
  117. return "下单成功~";
  118. }
  119. }

菜单详情控制层:

  1. @Controller
  2. public class MenuDetailController {
  3. @Resource
  4. MenuDetailServiceImpl menuDetailService;
  5. @Resource
  6. MenuTypeServiceImpl menuTypeService;
  7. @Resource
  8. FileUpload fileUpload;
  9. /*主页*/ /*联合查询,根据menuId查询 */
  10. @RequestMapping({"/main","/","/index"})
  11. public String main(Model model,HttpSession session){
  12. //用于封装整合后的对象的集合
  13. List<MenuDetail> menus = new ArrayList<MenuDetail>();
  14. List<MenuType> types = menuTypeService.selectAllType(); //查询出所有类型对象
  15. //临时集合,用于存放需要移除的,0菜品的类型对象
  16. List<MenuType> temp = new ArrayList<MenuType>();
  17. //通过mt_id重新封装对象列表
  18. for (MenuType type : types){
  19. List<MenuDetail> menu = menuDetailService.selectByType(type.getMtId());
  20. //如果 当前分类没有菜品,则移除该分类,同时不添加
  21. if (menu.size() == 0){
  22. temp.add(type);
  23. }
  24. menus.addAll(menu);
  25. }
  26. //封装后的list
  27. model.addAttribute("menus",menus);
  28. //移除空的类型
  29. for (MenuType t : temp){
  30. types.remove(t);
  31. }
  32. model.addAttribute("types",types);
  33. return "main";
  34. }
  35. /*菜单管理 分页*/ /*新增模糊查询分页*/
  36. @RequestMapping("/menuManage")
  37. public String menuManage(@RequestParam(value = "mtId",defaultValue = "0") int mtId,
  38. @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
  39. @RequestParam(value = "msg",defaultValue = "no") String msg, //上传图片传过来的值
  40. @RequestParam(value = "search",defaultValue = "no") String search,
  41. Model model){
  42. Page<MenuDetail> page = new Page<>(pageNum,3);
  43. //根据mtId进行分页。 mtId=0 默认显示全部
  44. menuDetailService.selectPage(page,mtId);
  45. //根据搜索名分页,覆盖原来的page
  46. if(!search.equals("no")) {
  47. menuDetailService.selectPageByName(page,search);
  48. msg = "searchSuccess";
  49. }
  50. model.addAttribute("page",page);
  51. List<MenuType> types = menuTypeService.selectAllType();
  52. model.addAttribute("types",types);
  53. model.addAttribute("mtId",mtId); //激活标签
  54. model.addAttribute("msg",msg);
  55. return "menu/menuManage";
  56. }
  57. /*删除单品*/
  58. @RequestMapping("/deleteOneMenu/{mdId}/{mtId}")
  59. public String deleteOneMenu(@PathVariable(value = "mdId")int mdId, @PathVariable(value = "mtId")int mtId){
  60. int i = menuDetailService.deleteOneMenu(mdId);
  61. return "redirect:/menuManage?mtId=" + mtId;
  62. }
  63. /*上传图片*/
  64. @RequestMapping("/upLoadImg")
  65. public String upLoadImg(@RequestParam(value = "upLoadFile") MultipartFile upLoadFile,
  66. @RequestParam(value = "mdId")int mdId,
  67. @RequestParam(value = "mtId")int mtId, Model model){
  68. String msg = null;
  69. String imgPath = FileUpload.uploadFile(upLoadFile);
  70. //更新操作
  71. MenuDetail menuDetail = menuDetailService.selectById(mdId);
  72. System.out.println("menuDetail = " + menuDetail.getMdName());
  73. menuDetail.setMdUrl(imgPath);
  74. menuDetailService.updateMenu(menuDetail);
  75. if(imgPath == null){
  76. msg = "uploadFault";
  77. return "redirect:/menuManage?mtId="+mtId+"&msg="+msg;
  78. }
  79. System.out.println("imgPath = " + imgPath);
  80. msg = "uploadSuccess";
  81. return "redirect:/menuManage?mtId="+mtId+"&msg="+msg;
  82. }
  83. @ResponseBody
  84. @RequestMapping("/insertMenu")
  85. public String insertMenu(MenuDetail menuDetail){
  86. menuDetailService.insertMenu(menuDetail);
  87. return "已成功新添菜品:"+menuDetail.getMdName();
  88. }
  89. @ResponseBody
  90. @RequestMapping("/updateMenu")
  91. public String updateMenu(MenuDetail menuDetail){
  92. MenuDetail tempMenu = menuDetailService.selectById(menuDetail.getMdId()); //原来数据库中的数据
  93. tempMenu.setMdName(menuDetail.getMdName());
  94. tempMenu.setMdPrice(menuDetail.getMdPrice());
  95. tempMenu.setMdAmount(menuDetail.getMdAmount());
  96. tempMenu.setMdNew(menuDetail.getMdNew());
  97. tempMenu.setMdStar(menuDetail.getMdStar());
  98. tempMenu.setMtId(menuDetail.getMtId()); //重新赋值
  99. menuDetailService.updateMenu(tempMenu);
  100. return menuDetail.getMdName()+"更新成功!";
  101. }
  102. }

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

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

闽ICP备14008679号