赞
踩
基于javaweb+mysql的springboot+mybatis网上订餐在线点餐管理系统(前台、后台)(java+springboot+ssm+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
前台用户:查看菜品、点餐下单、确认收货、评论等……
后台管理员:管理用户、订单、分类、交易、公告等……
前台
后台
技术框架
SpringBoot SpringMVC MyBatis JSP JavaScript jQuery……
基于javaweb+mysql的SpringBoot+MyBatis网上订餐在线点餐管理系统(前台、后台)(java+springboot+ssm+jsp+mysql)
/** * 从购物车删除 */ @PostMapping("/toDelete") public String toDelete(Integer productId, HttpSession session, Model model) { Product product = productService.findProductById(productId); System.out.println(product); ((Map<Product, Integer>) session.getAttribute("cart")).remove(product); System.out.println("size:" + ((Map<Product, Integer>) session.getAttribute("cart")).size()); return "/pages/order/cart"; } /** * 去支付订单页面 */ @PostMapping("/toOrder") public String toOrder(HttpSession session, String[] buyNum, Model model,@RequestParam("id") Integer[] id, @RequestParam("checkId") Integer[] checkId) { //1-获取session中用户基本信息 和详细信息 User user = (User) session.getAttribute("user"); UserInfo dbUserInfo = userService.findAdressByUserId(user.getId().toString()); //2-将购物车内的*全部*商品id和对应购买数量放入map中 key:商品id value:购买数量 Map<Integer,Integer> map = new HashMap<>(); for (int i = 0; i < id.length; i++){ map.put(id[i],Integer.parseInt(buyNum[i])); } //3-创建我的订单map集合 key:product产品信息 value:购买数量 Subject subject = SecurityUtils.getSubject(); Map<Product, Integer> myCartMap = new HashMap<>(); subject.getSession().setAttribute("myCartMap", myCartMap); Map<Product, Integer> myOrder = (HashMap<Product, Integer>) session.getAttribute("myCartMap"); //4-从存储有全部商品和购买数量的map中 取出 被选中的信息(checkbox)放到我的订单map中 for (Integer cId :checkId){ Product dbProduct = productService.findProductById(cId); myOrder.put(dbProduct,map.get(cId)); } model.addAttribute("myOrder", myOrder); model.addAttribute("userInfo", dbUserInfo); return "pages/order/pay_order"; } /** * 支付订单 */ @PostMapping("/order") public String order(HttpServletRequest request, HttpServletResponse response, String addressInfo, @RequestParam("id") Integer[] ids, HttpSession session) throws Exception { response.setContentType("text/html;charset=utf-8"); //1-生成订单编号 String orderId = UUID.randomUUID().toString(); User user = (User) session.getAttribute("user"); Map<Product, Integer> myCartMap = (Map<Product, Integer>) session.getAttribute("myCartMap");
userService.updateUserById(user); return "redirect:/personal_info"; } /* @RequestMapping("/admin/check") @ResponseBody public String checkPassowrd(User user, String npassword){ *//* String password = userService.findUserByUserId(user.getUserId()).getPassword(); if(user.getPassword().equals(password)){ user.setPassword(npassword); userService.updateUserPassword(user); return "true"; }else{ return "false"; }*//* return "false"; }*/ @RequestMapping("/addAdmin") public String addAdmin(User user) { userService.addUser(user); return "redirect:/admin/toMemberList"; } @RequestMapping("/deleteAdmins") public String deleteAdmins(@RequestParam("userId") String[] userIds){ userService.deleteAdminsById(userIds); return "redirect:/admin/toMemberList"; } @RequestMapping("/admin/selectUser") public String selectUser(String userName, Model model){ List<User> dbUserList = userService.findUserByUsername(userName); model.addAttribute("userList", dbUserList); return "/admin/member/member_list"; } @PostMapping("/admin/stopStatus") public void stopState(String userId) { int status = 0; userService.updateUserStatus(userId, status); } @PostMapping("/admin/startStatus") public void startState(String userId) { int status = 1;
*/ @Bean public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() { return new LifecycleBeanPostProcessor(); } /** * 开启Shiro的注解(如@RequiresRoles, @RequiresPermissions),需借助SpringAOP扫描使用Shiro注解的类,并在必要时进行安全逻辑验证 * 配置以下两个bean(DefaultAdvisorAutoProxyCreator(可选)和AuthorizationAttributeSourceAdvisor)即可实现此功能 * @return * @return */ @Bean @DependsOn({"lifecycleBeanPostProcessor"}) public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() { DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); advisorAutoProxyCreator.setProxyTargetClass(true); return advisorAutoProxyCreator; } @Bean public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor(); authorizationAttributeSourceAdvisor.setSecurityManager(securityManager); return authorizationAttributeSourceAdvisor; } } /** 前端product模块相关的controller */ @Controller public class ProductController { @Autowired private ProductService productService; @RequestMapping("/toList")
后端product模块相关的controller */ @Controller public class Back_ProductController { @Autowired private ProductService productService; @Autowired private ProductKindService productKindService; /** * 按条件查找数据--模糊查询 * @return */ @RequestMapping("/admin/toSelect") public String toSelect(@RequestParam("Pname") String Pname, Model model) { List<Product> list = productService.findAllProductCondition(Pname); model.addAttribute("productList", list); return "/admin/product/product_list"; } /** * * 后台展示商品列表 */ @RequestMapping("/admin/toProductList") public String toProductList(@RequestParam(required = true, defaultValue = "1") Integer page, Model model,String errorInfo) { if(StringUtil.isNotEmpty(errorInfo)){ model.addAttribute("errorInfo",errorInfo); } PageHelper.startPage(page, 10); //查询所有的商品信息 List<Product> productList = productService.findAllProductList(); model.addAttribute("productList", productList); PageInfo<Product> pageInfo = new PageInfo(productList); model.addAttribute("page", pageInfo); return "/admin/product/product_list"; }
/** 公告相关controller */ @Controller public class Back_NoticeController { @Autowired private NoticeService noticeService; /** * 展示公告列表 * @return */ @RequestMapping("/admin/toNoticeList") public String sortAds(@RequestParam(required = true, defaultValue = "1") Integer page,Model model) { PageHelper.startPage(page, 10); List<Notice> noticeList = noticeService.findAll(); model.addAttribute("noticeList",noticeList); PageInfo<Notice> p = new PageInfo<>(noticeList); model.addAttribute("page", p); return "/admin/notice/notice_list"; } /** * 创建公告 */ @RequestMapping("/admin/createNotice") public String createNotice(String title,String content,int status){ noticeService.addNotice(title,content,status); return "redirect:/admin/toNoticeList"; } /** * 修改公告
return ResponseMessageEnum.FAIL.getCode(); } return ResponseMessageEnum.SUCCESS.getCode(); } } /** */ @Controller public class Back_AdminController { @Autowired private UserService userService; @Autowired private RoleService roleService; @GetMapping("/admin/toMemberList") public String toMemberList(Model model){ List<User> allUser = userService.findAllUser(); List<Role> roleList = roleService.findRoleList(); model.addAttribute("userList",allUser); model.addAttribute("roleList", roleList); return "/admin/member/member_list"; } /** * * @param session 前台传过来的管理员的session,里面存有user对象 */ @GetMapping("/admin/personalInfo") public String findUserByUserId(HttpSession session, Model model){
String addressInfo, @RequestParam("id") Integer[] ids, HttpSession session) throws Exception { response.setContentType("text/html;charset=utf-8"); //1-生成订单编号 String orderId = UUID.randomUUID().toString(); User user = (User) session.getAttribute("user"); Map<Product, Integer> myCartMap = (Map<Product, Integer>) session.getAttribute("myCartMap"); //1-保存订单信息 orderService.saveOrder(user,ids, myCartMap, orderId); //--------------------------------------支付操作未实现-------------------------- //2-支付成功后修改订单状态 orderService.updateOrderStatus(0, orderId); //3-清空购物车 List<Product> list = productService.findProductsById(ids); for (Product product:list) { myCartMap.remove(product); } System.out.println("size:"+myCartMap.size()); return "pages/order/confirm"; } } /** 登录相关的controller */ @Controller public class LoginController { @Autowired private UserService userService;
Product product = productService.findProductById(id); //2-查询热门商品信息列表 List<Product> hotProductList = new ArrayList<>(); //2-1-从热门商品表中取出两个 productService.findProductBannerByCount(2).forEach(productBanner -> { Product dbProduct = productService.findProductById(productBanner.getProductId()); if(dbProduct != null){ hotProductList.add(dbProduct); } }); model.addAttribute("product",product); model.addAttribute("HotProductList",hotProductList); //3-跳转到商品详情页面 return "/pages/list/detail"; } } /** */ public class ObjectExcelViewOrder extends AbstractExcelView { private String fileName; private String excelTitle; public ObjectExcelViewOrder(String fileName, String excelTitle){ this.fileName = fileName; this.excelTitle = excelTitle; } @SuppressWarnings("deprecation") @Override protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { //Date date = new Date(); //String filename = Tools.date2Str(date, "yyyyMMddHHmmss"); HSSFSheet sheet =sheet = workbook.createSheet("sheet1"); HSSFCell cell = getCell(sheet, 0, 0);
return "/admin/adminAnsEva"; } @RequestMapping("/admin/ansEva") public String ansEva(String orderId,String ansContent,Integer orderStatus){ evaService.saveAnsEva(orderId,ansContent); orderService.updateOrderStatus(orderStatus,orderId); return "redirect:/admin/toOrderList"; } //跳转到订单详情页面 @RequestMapping("/admin/orderDetailed") public String orderDetailed(String orderId,Model model){ Order order = orderService.findListByOrderId(orderId); model.addAttribute("order",order); return "/admin/order/order_detailed"; } /** * 根据订单状态查询订单 */ @RequestMapping("/admin/searchOrderList") public String searchOrderList(Integer status,Model model){ List<Order> orderList = orderService.findOrderByStatus(status); model.addAttribute("orderList",orderList); return "/admin/toOrderList"; } /* * 导出到excel * @return */ @RequestMapping("/admin/downloadInfoToExcel") public ModelAndView downloadInfoToExcel() { System.out.println("导出到excel"); ModelAndView mv = new ModelAndView(); try { //1-根据id数组获取数据库数据 List<Object> dataList = getExcelDataList(); //2-获取列标题和封装数据
private RoleService roleService; @GetMapping("/admin/toMemberList") public String toMemberList(Model model){ List<User> allUser = userService.findAllUser(); List<Role> roleList = roleService.findRoleList(); model.addAttribute("userList",allUser); model.addAttribute("roleList", roleList); return "/admin/member/member_list"; } /** * * @param session 前台传过来的管理员的session,里面存有user对象 */ @GetMapping("/admin/personalInfo") public String findUserByUserId(HttpSession session, Model model){ Integer userId = ((User) session.getAttribute("user")).getId(); User user = userService.findUserInfo(userId); model.addAttribute("user", user); return "/admin/member/personal_info"; } @PostMapping("/admin/updateAdmin") public String updateUser(User user) { userService.updateUser(user); return "redirect:/personal_info"; } @GetMapping("/admin/updateAdminById") public String updateUserById(User user) { userService.updateUserById(user); return "redirect:/personal_info"; } /* @RequestMapping("/admin/check") @ResponseBody public String checkPassowrd(User user, String npassword){ *//* String password = userService.findUserByUserId(user.getUserId()).getPassword(); if(user.getPassword().equals(password)){ user.setPassword(npassword); userService.updateUserPassword(user); return "true";
//1-如果username已经存在 if (userService.finuserByUsername(userDTO.getUserName()) != null) { model.addAttribute("errorInfo","该用户名已经被注册"); return "/register"; } //2-如果username不存在 保存user信息 userService.registerUser(userDTO); return "/login"; } /** * 退出登录 */ @GetMapping("/loginOut") public String loginOut() { //1-通过subject进行登出操作 Subject subject = SecurityUtils.getSubject(); subject.getSession().removeAttribute("user"); subject.getSession().removeAttribute("roleId"); return "redirect:/index"; } /** * 获取验证码 * @param response * @param request */ @GetMapping(value = "getCode") public void getCode(HttpServletResponse response, HttpServletRequest request) { VerifyCode vc = new VerifyCode(); try { vc.drawImage(response.getOutputStream()); } catch (IOException e) { e.printStackTrace(); } String code = vc.getCode(); request.getSession().setAttribute("code", code); } /** * 校验验证码是否正确 */ @PostMapping("inputCode") @ResponseBody public Integer inputCode(HttpServletRequest request) { String code = (String) request.getSession().getAttribute("code"); String inputCode = request.getParameter("inputCode"); System.out.println("> > >" + code); System.out.println("input> > >" + inputCode); if (!code.toLowerCase().equals(inputCode.toLowerCase())) {
/** * */ @Controller public class UserController { @Autowired private OrderService orderService; @Autowired private UserService userService; @Autowired private EvaService evaService; @Autowired private LeaveService leaveService; /** * 去用户中心 */ @GetMapping("/toUserCenter") public String userCenter(Model model,HttpSession session){ User user = (User) session.getAttribute("user"); if(user == null){ return "/login"; } User userInfos = userService.findUserInfo(user.getId()); model.addAttribute("userInfos",userInfos); return "/pages/user/user_center"; } /** * 去我的订单
/** * 退出登录 */ @GetMapping("/loginOut") public String loginOut() { //1-通过subject进行登出操作 Subject subject = SecurityUtils.getSubject(); subject.getSession().removeAttribute("user"); subject.getSession().removeAttribute("roleId"); return "redirect:/index"; } /** * 获取验证码 * @param response * @param request */ @GetMapping(value = "getCode") public void getCode(HttpServletResponse response, HttpServletRequest request) { VerifyCode vc = new VerifyCode(); try { vc.drawImage(response.getOutputStream()); } catch (IOException e) { e.printStackTrace(); } String code = vc.getCode(); request.getSession().setAttribute("code", code); } /** * 校验验证码是否正确 */ @PostMapping("inputCode") @ResponseBody public Integer inputCode(HttpServletRequest request) { String code = (String) request.getSession().getAttribute("code"); String inputCode = request.getParameter("inputCode"); System.out.println("> > >" + code); System.out.println("input> > >" + inputCode); if (!code.toLowerCase().equals(inputCode.toLowerCase())) { return ResponseMessageEnum.FAIL.getCode(); } return ResponseMessageEnum.SUCCESS.getCode(); } }
return shiroFilterFactoryBean; } @Bean public EhCacheManager ehCacheManager() { EhCacheManager cacheManager = new EhCacheManager(); return cacheManager; } /** * 不指定名字的话,自动创建一个方法名第一个字母小写的bean * *@Bean(name = "securityManager") * @return */ @Bean public SecurityManager securityManager(AuthRealm m) { DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); // 设置realm. securityManager.setRealm(m); return securityManager; } /** * 生命周期处理器--shiro * @return */ @Bean public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() { return new LifecycleBeanPostProcessor(); } /** * 开启Shiro的注解(如@RequiresRoles, @RequiresPermissions),需借助SpringAOP扫描使用Shiro注解的类,并在必要时进行安全逻辑验证 * 配置以下两个bean(DefaultAdvisorAutoProxyCreator(可选)和AuthorizationAttributeSourceAdvisor)即可实现此功能 * @return * @return */ @Bean @DependsOn({"lifecycleBeanPostProcessor"}) public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() { DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); advisorAutoProxyCreator.setProxyTargetClass(true); return advisorAutoProxyCreator; }
/** * 批量删除 商品类别 */ @RequestMapping("/admin/batchtDeleteProduct") public String batchDeleteClassify(@RequestParam("id") Integer[] kindIds){ productKindService.batchDeletekind(kindIds); return "redirect:/admin/toProductClassifyList"; } /** * 查询全部分类 */ @RequestMapping(value="/admin/productKind/list",produces = "application/json;charset=utf-8") @ResponseBody public Object productKind(){ List productKindList= productService.findAllProductKindNameList(); return ResponseMessageEnum.SUCCESS.appendObjectToString(productKindList); } //--------------------------------------------------------------------------------------------------------------- @RequestMapping("/admin/toProductBanner") public String toProductBanner(Model model,@RequestParam(required = true, defaultValue = "1") Integer page){ PageHelper.startPage(page,5); List<ProductBanner> productBannerList = productService.findAllProductBanner(); PageInfo<ProductBanner> pageInfo = new PageInfo<>(productBannerList); model.addAttribute("page",pageInfo); model.addAttribute("productBannerList",productBannerList); return "/admin/product/product_banner_list"; } @RequestMapping("/admin/toAddProductBanner") public String toAddProductBanner(){ return "/admin/product/product_banner_edit"; } /** *选择上架状态 并且未关联热门的商品 */ @GetMapping(value = "/admin/validProduct/list" ,produces = "application/json;charset=utf-8") @ResponseBody
try { //1-根据id数组获取数据库数据 List<Object> dataList = getExcelDataList(); //2-获取列标题和封装数据 Map<String, Object> dataMap = getTitleArrayAndVarList(dataList); //3-获取Excel表格文件名和表格标题 Map<String, String> excelMap = getExcelTitleAndFileName(); //4-创建AbstractExcelView AbstractExcelView erv = getAbstractExcelView(excelMap); //ObjectExcelViewOrderOperation erv = new ObjectExcelViewOrderOperation(excelMap.get("fileName"),excelMap.get("excelTitle")); mv = new ModelAndView(erv, dataMap); } catch (Exception e) { e.printStackTrace(); } return mv; } /** *@描述 1-1-从数据库获取数据 */ protected List<Object> getExcelDataList(){ try { List<Object> dataList = orderService.find4ExcelDown(); return dataList; } catch (Exception e) { e.printStackTrace(); return null; } } /** *@描述 1-2-导出Excel-自定义列标题和数据 */ protected Map<String,Object> getTitleArrayAndVarList(List<Object> dataList) { Map<String,Object> dataMap = new HashMap<String,Object>(); //1-标题 String[] titleArray = { "订单序号", "订单编号", "订单金额", "收货人", "收获地址", "下单时间", "订单状态" }; dataMap.put("titles", Arrays.asList(titleArray)); //2-数据 List<OrderExcelExportVO> varList = new ArrayList<OrderExcelExportVO>(); for(int i=0;i<dataList.size();i++){ OrderExcelExportVO data = (OrderExcelExportVO)dataList.get(i); List<Object> vpd = new ArrayList<>(); varList.add(data);
} @RequestMapping("/advertising") public String advertising() { return "/admin/advertising"; } @RequestMapping("/admin/transaction") public String transaction() { return "/admin/order/transaction"; } @RequestMapping("/amounts") public String amounts() { return "/admin/Amounts"; } @RequestMapping("/orderHandling") public String orderHandling() { return "/admin/Order_handling"; } @RequestMapping("/coverManagement") public String coverManagement() { return "/admin/Cover_management"; } @RequestMapping("/userList") public String userList() { return "/admin/user_list"; } @RequestMapping("/memberGrading") public String memberGrading() { return "/admin/member-Grading"; } @RequestMapping("/integration") public String integration() { return "/admin/integration"; } @RequestMapping("/feedBack") public String feedBack() { return "/admin/Feedback"; } @RequestMapping("/systems") public String systems() { return "/admin/Systems"; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。