一、项目简述
本系统主要实现的功能有: 网上商城系统,前台+后台管理,用户注册,登录,上架展示,分组展示,搜索,收货地址管理,购物车管理,添加,购买,个人信息修改。订单查询等等,后台商品管理,分类管理,库存管理,订单管理,评论管理,用户管理,信息修改等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: Springboot+ SpringMVC + MyBatis + Jsp + Html+ JavaScript + JQuery + Ajax + maven等等。
后台管理-账户页控制层:
/** * 后台管理-账户页 * @author yy */ @Controller public class AccountController extends BaseController{ @Resource(name = "adminService") private AdminService adminService; //转到后台管理-账户页-ajax @RequestMapping(value = "admin/account", method = RequestMethod.GET) public String goToPage(HttpSession session, Map<String, Object> map){ logger.info("获取管理员信息"); Object adminId = checkAdmin(session); if(adminId == null){ return "admin/include/loginMessage"; } logger.info("获取目前登录的管理员信息,管理员ID:{}",adminId); Admin admin = adminService.get(null,Integer.parseInt(adminId.toString())); map.put("admin",admin); logger.info("转到后台管理-账户页-ajax方式"); return "admin/accountManagePage"; } //退出当前账号 @RequestMapping(value = "admin/account/logout", method = RequestMethod.GET) public String logout(HttpSession session) { Object o = session.getAttribute("adminId"); if (o == null) { logger.info("无相关信息,返回管理员登陆页"); } else { session.removeAttribute("adminId"); session.invalidate(); logger.info("登录信息已清除,返回管理员登陆页"); } return "redirect:/admin/login"; } //管理员头像上传 @ResponseBody @RequestMapping(value = "admin/uploadAdminHeadImage", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") public String uploadAdminHeadImage(@RequestParam MultipartFile file, HttpSession session) { String originalFileName = file.getOriginalFilename(); logger.info("获取图片原始文件名:{}", originalFileName); assert originalFileName != null; String extension = originalFileName.substring(originalFileName.lastIndexOf('.')); //生成随机名 String fileName = UUID.randomUUID() + extension; //获取上传路径 String filePath = session.getServletContext().getRealPath("/") + "res/images/item/adminProfilePicture/" + fileName; logger.info("文件上传路径:{}", filePath); JSONObject jsonObject = new JSONObject(); try { logger.info("文件上传中..."); file.transferTo(new File(filePath)); logger.info("文件上传成功!"); jsonObject.put("success", true); jsonObject.put("fileName", fileName); } catch (IOException e) { logger.warn("文件上传失败!"); e.printStackTrace(); jsonObject.put("success", false); } return jsonObject.toJSONString(); } //更新管理员信息 @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) @ResponseBody @RequestMapping(value = "admin/account/{admin_id}", method = RequestMethod.PUT, produces = "application/json;charset=UTF-8") public String updateAdmin(HttpSession session, @RequestParam String admin_nickname/*管理员昵称*/, @RequestParam(required = false) String admin_password/*管理员当前密码*/, @RequestParam(required = false) String admin_newPassword/*管理员新密码*/, @RequestParam(required = false) String admin_profile_picture_src/*管理员头像路径*/, @PathVariable("admin_id") String admin_id/*管理员编号*/) { logger.info("获取管理员信息"); Object adminId = checkAdmin(session); if (adminId == null) { return "admin/include/loginMessage"; } JSONObject jsonObject = new JSONObject(); Admin putAdmin = new Admin(); putAdmin.setAdmin_id(Integer.valueOf(admin_id)); putAdmin.setAdmin_nickname(admin_nickname); if (admin_password != null && !"".equals(admin_password) && admin_newPassword != null && !"".equals(admin_newPassword)) { logger.info("获取需要修改的管理员信息"); Admin admin = adminService.get(null, Integer.valueOf(adminId.toString())); if (adminService.login(admin.getAdmin_name(), admin_password) != null) { logger.info("原密码正确"); putAdmin.setAdmin_password(admin_newPassword); } else { logger.info("原密码错误,返回错误信息"); jsonObject.put("success", false); jsonObject.put("message", "原密码输入有误!"); return jsonObject.toJSONString(); } } if (admin_profile_picture_src != null && !"".equals(admin_profile_picture_src)) { logger.info("管理员头像路径为{}", admin_profile_picture_src); putAdmin.setAdmin_profile_picture_src(admin_profile_picture_src.substring(admin_profile_picture_src.lastIndexOf("/") + 1)); } logger.info("更新管理员信息,管理员ID值为:{}", admin_id); Boolean yn = adminService.update(putAdmin); if (yn) { logger.info("更新成功!"); jsonObject.put("success", true); session.removeAttribute("adminId"); session.invalidate(); logger.info("登录信息已清除"); } else { jsonObject.put("success", false); logger.warn("更新失败!事务回滚"); throw new RuntimeException(); } return jsonObject.toJSONString(); } }
后台管理-主页控制层:
/** * 后台管理-主页 */ @Controller public class AdminHomeController extends BaseController { @Resource(name = "adminService") private AdminService adminService; @Resource(name = "productOrderService") private ProductOrderService productOrderService; @Resource(name = "productService") private ProductService productService; @Resource(name = "userService") private UserService userService; /** * 转到后台管理-主页 * @param session session对象 * @param map 前台传入的Map * @return 响应数据 * @throws ParseException 转换异常 */ @RequestMapping(value = "admin", method = RequestMethod.GET) public String goToPage(HttpSession session, Map<String, Object> map) throws ParseException { logger.info("获取管理员信息"); Object adminId = checkAdmin(session); if (adminId == null) { return "redirect:/admin/login"; } Admin admin = adminService.get(null, Integer.parseInt(adminId.toString())); map.put("admin", admin); logger.info("获取统计信息"); //产品总数 Integer productTotal = productService.getTotal(null, new Byte[]{0, 2}); //用户总数 Integer userTotal = userService.getTotal(null); //订单总数 Integer orderTotal = productOrderService.getTotal(null, new Byte[]{3}); logger.info("获取图表信息"); map.put("jsonObject", getChartData(null,null,7)); map.put("productTotal", productTotal); map.put("userTotal", userTotal); map.put("orderTotal", orderTotal); logger.info("转到后台管理-主页"); return "admin/homePage"; } /** * 转到后台管理-主页(ajax方式) * @param session session对象 * @param map 前台传入的Map * @return 响应数据 * @throws ParseException 转换异常 */ @RequestMapping(value = "admin/home", method = RequestMethod.GET) public String goToPageByAjax(HttpSession session, Map<String, Object> map) throws ParseException { logger.info("获取管理员信息"); Object adminId = checkAdmin(session); if (adminId == null) { return "admin/include/loginMessage"; } Admin admin = adminService.get(null, Integer.parseInt(adminId.toString())); map.put("admin", admin); logger.info("获取统计信息"); Integer productTotal = productService.getTotal(null, new Byte[]{0, 2}); Integer userTotal = userService.getTotal(null); Integer orderTotal =