赞
踩
基于javaweb+mysql的springboot网上商城系统设计和实现(java+springboot+ssm+mysql+thymeleaf+html+maven)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot网上商城系统设计和实现(java+springboot+ssm+mysql+thymeleaf+html+maven)
一、项目简述
本系统主要实现的功能有: OnlineMall项目是一套电商系统,包括OnlineMall商城系 统及OnlineMall商城后台管理^统,基于Spring Boot 2.X 及相关技术栈开发。前台商城系统包含首页门户、商品分 类、新品上线、首页轮播、商品推荐、商品搜索、商品展 示、购物车、订单结算、订单流程、个人订单管理、会员 中心、帮助中心等模块。后台管理系统包含数据面板、轮 播图管理、商品管理、订单管理、会员管理、分类管理、 设置等模块。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等
* 修改 */ @RequestMapping(value = "/indexConfigs/update", method = RequestMethod.POST) @ResponseBody public Result update(@RequestBody IndexConfig indexConfig) { if (Objects.isNull(indexConfig.getConfigType()) || Objects.isNull(indexConfig.getConfigId()) || StringUtils.isEmpty(indexConfig.getConfigName()) || Objects.isNull(indexConfig.getConfigRank())) { return ResultGenerator.genFailResult("参数异常!"); } String result = newBeeMallIndexConfigService.updateIndexConfig(indexConfig); if (ServiceResultEnum.SUCCESS.getResult().equals(result)) { return ResultGenerator.genSuccessResult(); } else { return ResultGenerator.genFailResult(result); } } /** * 详情 */ @GetMapping("/indexConfigs/info/{id}") @ResponseBody public Result info(@PathVariable("id") Long id) { IndexConfig config = newBeeMallIndexConfigService.getIndexConfigById(id); if (config == null) { return ResultGenerator.genFailResult("未查询到数据"); } return ResultGenerator.genSuccessResult(config); } /** * 删除 */ @RequestMapping(value = "/indexConfigs/delete", method = RequestMethod.POST) @ResponseBody public Result delete(@RequestBody Long[] ids) { if (ids.length < 1) { return ResultGenerator.genFailResult("参数异常!"); } if (newBeeMallIndexConfigService.deleteBatch(ids)) { return ResultGenerator.genSuccessResult(); } else { return ResultGenerator.genFailResult("删除失败"); } }
} else { session.setAttribute("errorMsg", "登陆失败"); return "admin/login"; } } @GetMapping("/profile") public String profile(HttpServletRequest request) { Integer loginUserId = (int) request.getSession().getAttribute("loginUserId"); AdminUser adminUser = adminUserService.getUserDetailById(loginUserId); if (adminUser == null) { return "admin/login"; } request.setAttribute("path", "profile"); request.setAttribute("loginUserName", adminUser.getLoginUserName()); request.setAttribute("nickName", adminUser.getNickName()); return "admin/profile"; } @PostMapping("/profile/password") @ResponseBody public String passwordUpdate(HttpServletRequest request, @RequestParam("originalPassword") String originalPassword, @RequestParam("newPassword") String newPassword) { if (StringUtils.isEmpty(originalPassword) || StringUtils.isEmpty(newPassword)) { return "参数不能为空"; } Integer loginUserId = (int) request.getSession().getAttribute("loginUserId"); if (adminUserService.updatePassword(loginUserId, originalPassword, newPassword)) { //修改成功后清空session中的数据,前端控制跳转至登录页 request.getSession().removeAttribute("loginUserId"); request.getSession().removeAttribute("loginUser"); request.getSession().removeAttribute("errorMsg"); return ServiceResultEnum.SUCCESS.getResult(); } else { return "修改失败"; } } @PostMapping("/profile/name") @ResponseBody public String nameUpdate(HttpServletRequest request, @RequestParam("loginUserName") String loginUserName, @RequestParam("nickName") String nickName) { if (StringUtils.isEmpty(loginUserName) || StringUtils.isEmpty(nickName)) { return "参数不能为空"; }
public Result login(@RequestParam("loginName") String loginName, @RequestParam("verifyCode") String verifyCode, @RequestParam("password") String password, HttpSession httpSession) { if (StringUtils.isEmpty(loginName)) { return ResultGenerator.genFailResult(ServiceResultEnum.LOGIN_NAME_NULL.getResult()); } if (StringUtils.isEmpty(password)) { return ResultGenerator.genFailResult(ServiceResultEnum.LOGIN_PASSWORD_NULL.getResult()); } if (StringUtils.isEmpty(verifyCode)) { return ResultGenerator.genFailResult(ServiceResultEnum.LOGIN_VERIFY_CODE_NULL.getResult()); } String kaptchaCode = httpSession.getAttribute(Constants.MALL_VERIFY_CODE_KEY) + ""; if (StringUtils.isEmpty(kaptchaCode) || !verifyCode.equals(kaptchaCode)) { return ResultGenerator.genFailResult(ServiceResultEnum.LOGIN_VERIFY_CODE_ERROR.getResult()); } //todo 清verifyCode String loginResult = newBeeMallUserService.login(loginName, MD5Util.MD5Encode(password, "UTF-8"), httpSession); //登录成功 if (ServiceResultEnum.SUCCESS.getResult().equals(loginResult)) { return ResultGenerator.genSuccessResult(); } //登录失败 return ResultGenerator.genFailResult(loginResult); } @PostMapping("/register") @ResponseBody public Result register(@RequestParam("loginName") String loginName, @RequestParam("verifyCode") String verifyCode, @RequestParam("password") String password, HttpSession httpSession) { if (StringUtils.isEmpty(loginName)) { return ResultGenerator.genFailResult(ServiceResultEnum.LOGIN_NAME_NULL.getResult()); } if (StringUtils.isEmpty(password)) { return ResultGenerator.genFailResult(ServiceResultEnum.LOGIN_PASSWORD_NULL.getResult()); } if (StringUtils.isEmpty(verifyCode)) { return ResultGenerator.genFailResult(ServiceResultEnum.LOGIN_VERIFY_CODE_NULL.getResult()); } String kaptchaCode = httpSession.getAttribute(Constants.MALL_VERIFY_CODE_KEY) + ""; if (StringUtils.isEmpty(kaptchaCode) || !verifyCode.equals(kaptchaCode)) { return ResultGenerator.genFailResult(ServiceResultEnum.LOGIN_VERIFY_CODE_ERROR.getResult()); } //todo 清verifyCode String registerResult = newBeeMallUserService.register(loginName, password); //注册成功 if (ServiceResultEnum.SUCCESS.getResult().equals(registerResult)) {
return false; } return mallUserMapper.lockUserBatch(ids, lockStatus) > 0; } } /** */ @Controller @RequestMapping("/admin") public class NewBeeMallCarouselController { @Resource NewBeeMallCarouselService newBeeMallCarouselService; @GetMapping("/carousels") public String carouselPage(HttpServletRequest request) { request.setAttribute("path", "newbee_mall_carousel"); return "admin/newbee_mall_carousel"; } /** * 列表 */ @RequestMapping(value = "/carousels/list", method = RequestMethod.GET) @ResponseBody public Result list(@RequestParam Map<String, Object> params) { if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) { return ResultGenerator.genFailResult("参数异常!"); } PageQueryUtil pageUtil = new PageQueryUtil(params); return ResultGenerator.genSuccessResult(newBeeMallCarouselService.getCarouselPage(pageUtil));
responseOutputStream.flush(); responseOutputStream.close(); } @GetMapping("/common/mall/kaptcha") public void mallKaptcha(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { com.google.code.kaptcha.impl.DefaultKaptcha newBeeMallLoginKaptcha = new com.google.code.kaptcha.impl.DefaultKaptcha(); Properties properties = new Properties(); properties.put("kaptcha.border", "no"); properties.put("kaptcha.textproducer.font.color", "27,174,171"); properties.put("kaptcha.noise.color", "20,33,42"); properties.put("kaptcha.textproducer.font.size", "30"); properties.put("kaptcha.image.width", "110"); properties.put("kaptcha.image.height", "40"); properties.put("kaptcha.session.key", Constants.MALL_VERIFY_CODE_KEY); properties.put("kaptcha.textproducer.char.space", "2"); properties.put("kaptcha.textproducer.char.length", "6"); Config config = new Config(properties); newBeeMallLoginKaptcha.setConfig(config); byte[] captchaOutputStream = null; ByteArrayOutputStream imgOutputStream = new ByteArrayOutputStream(); try { //生产验证码字符串并保存到session中 String verifyCode = newBeeMallLoginKaptcha.createText(); httpServletRequest.getSession().setAttribute(Constants.MALL_VERIFY_CODE_KEY, verifyCode); BufferedImage challenge = newBeeMallLoginKaptcha.createImage(verifyCode); ImageIO.write(challenge, "jpg", imgOutputStream); } catch (IllegalArgumentException e) { httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); return; } captchaOutputStream = imgOutputStream.toByteArray(); httpServletResponse.setHeader("Cache-Control", "no-store"); httpServletResponse.setHeader("Pragma", "no-cache"); httpServletResponse.setDateHeader("Expires", 0); httpServletResponse.setContentType("image/jpeg"); ServletOutputStream responseOutputStream = httpServletResponse.getOutputStream(); responseOutputStream.write(captchaOutputStream); responseOutputStream.flush(); responseOutputStream.close(); } }
//返回成功 Result result = ResultGenerator.genSuccessResult(); return result; } } } /** */ @Controller @RequestMapping("/admin") public class NewBeeMallOrderController { @Resource private NewBeeMallOrderService newBeeMallOrderService; @GetMapping("/orders") public String ordersPage(HttpServletRequest request) { request.setAttribute("path", "orders");
return ResultGenerator.genFailResult("未查询到数据"); } return ResultGenerator.genSuccessResult(goodsCategory); } /** * 分类删除 */ @RequestMapping(value = "/categories/delete", method = RequestMethod.POST) @ResponseBody public Result delete(@RequestBody Integer[] ids) { if (ids.length < 1) { return ResultGenerator.genFailResult("参数异常!"); } if (newBeeMallCategoryService.deleteBatch(ids)) { return ResultGenerator.genSuccessResult(); } else { return ResultGenerator.genFailResult("删除失败"); } } }
if (StringUtils.isEmpty(params.get("page"))) { params.put("page", 1); } params.put("limit", Constants.ORDER_SEARCH_PAGE_LIMIT); //封装我的订单数据 PageQueryUtil pageUtil = new PageQueryUtil(params); request.setAttribute("orderPageResult", newBeeMallOrderService.getMyOrders(pageUtil)); request.setAttribute("path", "orders"); return "mall/my-orders"; } @GetMapping("/saveOrder") public String saveOrder(HttpSession httpSession) { NewBeeMallUserVO user = (NewBeeMallUserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY); List<NewBeeMallShoppingCartItemVO> myShoppingCartItems = newBeeMallShoppingCartService.getMyShoppingCartItems(user.getUserId()); if (StringUtils.isEmpty(user.getAddress().trim())) { //无收货地址 NewBeeMallException.fail(ServiceResultEnum.NULL_ADDRESS_ERROR.getResult()); } if (CollectionUtils.isEmpty(myShoppingCartItems)) { //购物车中无数据则跳转至错误页 NewBeeMallException.fail(ServiceResultEnum.SHOPPING_ITEM_ERROR.getResult()); } //保存订单并返回订单号 String saveOrderResult = newBeeMallOrderService.saveOrder(user, myShoppingCartItems); //跳转到订单详情页 return "redirect:/orders/" + saveOrderResult; } @PutMapping("/orders/{orderNo}/cancel") @ResponseBody public Result cancelOrder(@PathVariable("orderNo") String orderNo, HttpSession httpSession) { NewBeeMallUserVO user = (NewBeeMallUserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY); String cancelOrderResult = newBeeMallOrderService.cancelOrder(orderNo, user.getUserId()); if (ServiceResultEnum.SUCCESS.getResult().equals(cancelOrderResult)) { return ResultGenerator.genSuccessResult(); } else { return ResultGenerator.genFailResult(cancelOrderResult); } }
@Controller public class GoodsController { @Resource private NewBeeMallGoodsService newBeeMallGoodsService; @Resource private NewBeeMallCategoryService newBeeMallCategoryService; @GetMapping({"/search", "/search.html"}) public String searchPage(@RequestParam Map<String, Object> params, HttpServletRequest request) { if (StringUtils.isEmpty(params.get("page"))) { params.put("page", 1); } params.put("limit", Constants.GOODS_SEARCH_PAGE_LIMIT); //封装分类数据 if (params.containsKey("goodsCategoryId") && !StringUtils.isEmpty(params.get("goodsCategoryId") + "")) { Long categoryId = Long.valueOf(params.get("goodsCategoryId") + ""); SearchPageCategoryVO searchPageCategoryVO = newBeeMallCategoryService.getCategoriesForSearch(categoryId); if (searchPageCategoryVO != null) { request.setAttribute("goodsCategoryId", categoryId); request.setAttribute("searchPageCategoryVO", searchPageCategoryVO); } } //封装参数供前端回显 if (params.containsKey("orderBy") && !StringUtils.isEmpty(params.get("orderBy") + "")) { request.setAttribute("orderBy", params.get("orderBy") + ""); } String keyword = ""; //对keyword做过滤 去掉空格 if (params.containsKey("keyword") && !StringUtils.isEmpty((params.get("keyword") + "").trim())) { keyword = params.get("keyword") + "";
if (currentGoodsCategory != null && currentGoodsCategory.getCategoryLevel() == NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()) { //查询所有的一级分类 List<GoodsCategory> firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()); //根据parentId查询当前parentId下所有的三级分类 List<GoodsCategory> thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(currentGoodsCategory.getParentId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); //查询当前三级分类的父级二级分类 GoodsCategory secondCategory = newBeeMallCategoryService.getGoodsCategoryById(currentGoodsCategory.getParentId()); if (secondCategory != null) { //根据parentId查询当前parentId下所有的二级分类 List<GoodsCategory> secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondCategory.getParentId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); //查询当前二级分类的父级一级分类 GoodsCategory firestCategory = newBeeMallCategoryService.getGoodsCategoryById(secondCategory.getParentId()); if (firestCategory != null) { //所有分类数据都得到之后放到request对象中供前端读取 request.setAttribute("firstLevelCategories", firstLevelCategories); request.setAttribute("secondLevelCategories", secondLevelCategories); request.setAttribute("thirdLevelCategories", thirdLevelCategories); request.setAttribute("firstLevelCategoryId", firestCategory.getCategoryId()); request.setAttribute("secondLevelCategoryId", secondCategory.getCategoryId()); request.setAttribute("thirdLevelCategoryId", currentGoodsCategory.getCategoryId()); } } } } } if (newBeeMallGoods.getGoodsCategoryId() == 0) { //查询所有的一级分类 List<GoodsCategory> firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()); if (!CollectionUtils.isEmpty(firstLevelCategories)) { //查询一级分类列表中第一个实体的所有二级分类 List<GoodsCategory> secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(firstLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); if (!CollectionUtils.isEmpty(secondLevelCategories)) { //查询二级分类列表中第一个实体的所有三级分类 List<GoodsCategory> thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); request.setAttribute("firstLevelCategories", firstLevelCategories); request.setAttribute("secondLevelCategories", secondLevelCategories); request.setAttribute("thirdLevelCategories", thirdLevelCategories); } } } request.setAttribute("goods", newBeeMallGoods); request.setAttribute("path", "goods-edit"); return "admin/newbee_mall_goods_edit"; } /** * 列表 */ @RequestMapping(value = "/goods/list", method = RequestMethod.GET) @ResponseBody public Result list(@RequestParam Map<String, Object> params) { if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {
@ResponseBody public Result save(@RequestBody NewBeeMallGoods newBeeMallGoods) { if (StringUtils.isEmpty(newBeeMallGoods.getGoodsName()) || StringUtils.isEmpty(newBeeMallGoods.getGoodsIntro()) || StringUtils.isEmpty(newBeeMallGoods.getTag()) || Objects.isNull(newBeeMallGoods.getOriginalPrice()) || Objects.isNull(newBeeMallGoods.getGoodsCategoryId()) || Objects.isNull(newBeeMallGoods.getSellingPrice()) || Objects.isNull(newBeeMallGoods.getStockNum()) || Objects.isNull(newBeeMallGoods.getGoodsSellStatus()) || StringUtils.isEmpty(newBeeMallGoods.getGoodsCoverImg()) || StringUtils.isEmpty(newBeeMallGoods.getGoodsDetailContent())) { return ResultGenerator.genFailResult("参数异常!"); } String result = newBeeMallGoodsService.saveNewBeeMallGoods(newBeeMallGoods); if (ServiceResultEnum.SUCCESS.getResult().equals(result)) { return ResultGenerator.genSuccessResult(); } else { return ResultGenerator.genFailResult(result); } } /** * 修改 */ @RequestMapping(value = "/goods/update", method = RequestMethod.POST) @ResponseBody public Result update(@RequestBody NewBeeMallGoods newBeeMallGoods) { if (Objects.isNull(newBeeMallGoods.getGoodsId()) || StringUtils.isEmpty(newBeeMallGoods.getGoodsName()) || StringUtils.isEmpty(newBeeMallGoods.getGoodsIntro()) || StringUtils.isEmpty(newBeeMallGoods.getTag()) || Objects.isNull(newBeeMallGoods.getOriginalPrice()) || Objects.isNull(newBeeMallGoods.getSellingPrice()) || Objects.isNull(newBeeMallGoods.getGoodsCategoryId()) || Objects.isNull(newBeeMallGoods.getStockNum()) || Objects.isNull(newBeeMallGoods.getGoodsSellStatus()) || StringUtils.isEmpty(newBeeMallGoods.getGoodsCoverImg()) || StringUtils.isEmpty(newBeeMallGoods.getGoodsDetailContent())) { return ResultGenerator.genFailResult("参数异常!");
request.setAttribute("configType", configType); return "admin/newbee_mall_index_config"; } /** * 列表 */ @RequestMapping(value = "/indexConfigs/list", method = RequestMethod.GET) @ResponseBody public Result list(@RequestParam Map<String, Object> params) { if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) { return ResultGenerator.genFailResult("参数异常!"); } PageQueryUtil pageUtil = new PageQueryUtil(params); return ResultGenerator.genSuccessResult(newBeeMallIndexConfigService.getConfigsPage(pageUtil)); } /** * 添加 */ @RequestMapping(value = "/indexConfigs/save", method = RequestMethod.POST) @ResponseBody public Result save(@RequestBody IndexConfig indexConfig) { if (Objects.isNull(indexConfig.getConfigType()) || StringUtils.isEmpty(indexConfig.getConfigName()) || Objects.isNull(indexConfig.getConfigRank())) { return ResultGenerator.genFailResult("参数异常!"); } String result = newBeeMallIndexConfigService.saveIndexConfig(indexConfig); if (ServiceResultEnum.SUCCESS.getResult().equals(result)) { return ResultGenerator.genSuccessResult(); } else { return ResultGenerator.genFailResult(result); } } /** * 修改 */ @RequestMapping(value = "/indexConfigs/update", method = RequestMethod.POST)
/** */ @Controller public class CommonController { @Autowired private DefaultKaptcha captchaProducer; @GetMapping("/common/kaptcha") public void defaultKaptcha(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { byte[] captchaOutputStream = null; ByteArrayOutputStream imgOutputStream = new ByteArrayOutputStream(); try { //生产验证码字符串并保存到session中 String verifyCode = captchaProducer.createText(); httpServletRequest.getSession().setAttribute("verifyCode", verifyCode); BufferedImage challenge = captchaProducer.createImage(verifyCode); ImageIO.write(challenge, "jpg", imgOutputStream); } catch (IllegalArgumentException e) { httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); return; } captchaOutputStream = imgOutputStream.toByteArray(); httpServletResponse.setHeader("Cache-Control", "no-store"); httpServletResponse.setHeader("Pragma", "no-cache"); httpServletResponse.setDateHeader("Expires", 0); httpServletResponse.setContentType("image/jpeg"); ServletOutputStream responseOutputStream = httpServletResponse.getOutputStream(); responseOutputStream.write(captchaOutputStream); responseOutputStream.flush(); responseOutputStream.close(); } @GetMapping("/common/mall/kaptcha") public void mallKaptcha(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
if (ids.length < 1) { return ResultGenerator.genFailResult("参数异常!"); } if (sellStatus != Constants.SELL_STATUS_UP && sellStatus != Constants.SELL_STATUS_DOWN) { return ResultGenerator.genFailResult("状态异常!"); } if (newBeeMallGoodsService.batchUpdateSellStatus(ids, sellStatus)) { return ResultGenerator.genSuccessResult(); } else { return ResultGenerator.genFailResult("修改失败"); } } } /** */ @Controller @RequestMapping("/admin") public class NewBeeMallGoodsCategoryController { @Resource private NewBeeMallCategoryService newBeeMallCategoryService; @GetMapping("/categories") public String categoriesPage(HttpServletRequest request, @RequestParam("categoryLevel") Byte categoryLevel, @RequestParam("parentId") Long parentId, @RequestParam("backParentId") Long backParentId) { if (categoryLevel == null || categoryLevel < 1 || categoryLevel > 3) { return "error/error_5xx"; } request.setAttribute("path", "newbee_mall_category"); request.setAttribute("parentId", parentId);
/** */ @Controller @RequestMapping("/admin") public class NewBeeMallUserController { @Resource private NewBeeMallUserService newBeeMallUserService; @GetMapping("/users") public String usersPage(HttpServletRequest request) { request.setAttribute("path", "users"); return "admin/newbee_mall_user"; } /** * 列表 */ @RequestMapping(value = "/users/list", method = RequestMethod.GET) @ResponseBody public Result list(@RequestParam Map<String, Object> params) { if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) { return ResultGenerator.genFailResult("参数异常!"); } PageQueryUtil pageUtil = new PageQueryUtil(params); return ResultGenerator.genSuccessResult(newBeeMallUserService.getNewBeeMallUsersPage(pageUtil)); } /** * 用户禁用与解除禁用(0-未锁定 1-已锁定) */ @RequestMapping(value = "/users/lock/{lockStatus}", method = RequestMethod.POST) @ResponseBody public Result delete(@RequestBody Integer[] ids, @PathVariable int lockStatus) { if (ids.length < 1) {
return "error/error_5xx"; } NewBeeMallGoods goods = newBeeMallGoodsService.getNewBeeMallGoodsById(goodsId); if (goods == null) { return "error/error_404"; } NewBeeMallGoodsDetailVO goodsDetailVO = new NewBeeMallGoodsDetailVO(); BeanUtil.copyProperties(goods, goodsDetailVO); goodsDetailVO.setGoodsCarouselList(goods.getGoodsCarousel().split(",")); request.setAttribute("goodsDetail", goodsDetailVO); return "mall/detail"; } } @Controller public class ErrorPageController implements ErrorController { private static ErrorPageController errorPageController; @Autowired private ErrorAttributes errorAttributes; private final static String ERROR_PATH = "/error"; public ErrorPageController(ErrorAttributes errorAttributes) { this.errorAttributes = errorAttributes; } public ErrorPageController() { if (errorPageController == null) { errorPageController = new ErrorPageController(errorAttributes); } } @RequestMapping(value = ERROR_PATH, produces = "text/html") public ModelAndView errorHtml(HttpServletRequest request) {
//有分类字段则查询相关分类数据返回给前端以供分类的三级联动显示 GoodsCategory currentGoodsCategory = newBeeMallCategoryService.getGoodsCategoryById(newBeeMallGoods.getGoodsCategoryId()); //商品表中存储的分类id字段为三级分类的id,不为三级分类则是错误数据 if (currentGoodsCategory != null && currentGoodsCategory.getCategoryLevel() == NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()) { //查询所有的一级分类 List<GoodsCategory> firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()); //根据parentId查询当前parentId下所有的三级分类 List<GoodsCategory> thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(currentGoodsCategory.getParentId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); //查询当前三级分类的父级二级分类 GoodsCategory secondCategory = newBeeMallCategoryService.getGoodsCategoryById(currentGoodsCategory.getParentId()); if (secondCategory != null) { //根据parentId查询当前parentId下所有的二级分类 List<GoodsCategory> secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondCategory.getParentId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); //查询当前二级分类的父级一级分类 GoodsCategory firestCategory = newBeeMallCategoryService.getGoodsCategoryById(secondCategory.getParentId()); if (firestCategory != null) { //所有分类数据都得到之后放到request对象中供前端读取 request.setAttribute("firstLevelCategories", firstLevelCategories); request.setAttribute("secondLevelCategories", secondLevelCategories); request.setAttribute("thirdLevelCategories", thirdLevelCategories); request.setAttribute("firstLevelCategoryId", firestCategory.getCategoryId()); request.setAttribute("secondLevelCategoryId", secondCategory.getCategoryId()); request.setAttribute("thirdLevelCategoryId", currentGoodsCategory.getCategoryId()); } } } } } if (newBeeMallGoods.getGoodsCategoryId() == 0) { //查询所有的一级分类 List<GoodsCategory> firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()); if (!CollectionUtils.isEmpty(firstLevelCategories)) { //查询一级分类列表中第一个实体的所有二级分类 List<GoodsCategory> secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(firstLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); if (!CollectionUtils.isEmpty(secondLevelCategories)) { //查询二级分类列表中第一个实体的所有三级分类 List<GoodsCategory> thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); request.setAttribute("firstLevelCategories", firstLevelCategories); request.setAttribute("secondLevelCategories", secondLevelCategories); request.setAttribute("thirdLevelCategories", thirdLevelCategories); } } } request.setAttribute("goods", newBeeMallGoods); request.setAttribute("path", "goods-edit"); return "admin/newbee_mall_goods_edit";
} String result = newBeeMallOrderService.checkOut(ids); if (ServiceResultEnum.SUCCESS.getResult().equals(result)) { return ResultGenerator.genSuccessResult(); } else { return ResultGenerator.genFailResult(result); } } /** * 关闭订单 */ @RequestMapping(value = "/orders/close", method = RequestMethod.POST) @ResponseBody public Result closeOrder(@RequestBody Long[] ids) { if (ids.length < 1) { return ResultGenerator.genFailResult("参数异常!"); } String result = newBeeMallOrderService.closeOrder(ids); if (ServiceResultEnum.SUCCESS.getResult().equals(result)) { return ResultGenerator.genSuccessResult(); } else { return ResultGenerator.genFailResult(result); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。