1. Controller要修改的有:
将 goodsForm.setType("粮食");
model.addAttribute("goodsForm",goodsForm);
改为 List<GoodsForm> commodityType = goodsService.getType(goodsForm);
goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId());//选择第一项的Id
model.addAttribute("goodsForm", goodsForm);
model.addAttribute("commodityType", commodityType));
其中 List<GoodsForm> commodityType = goodsService.getType(goodsForm);
model.addAttribute("commodityType",commodityType);
等价于 model.addAttribute("commodityType",goodsService.getType(goodsForm);
涉及要修改这几句代码的地方如下:
(1)AlipayController.java中value = "alipaySubmit" value = "replayAlipaySubmit" value = "guestAlipaySubmit"方法
其中value = "guestAlipaySubmit"方法中,先添加goodsForm.setCommodityId(alipayForm.getCommodityId());而且原本有的model.addAttribute("goodsForm", goodsForm);与新添加的model.addAttribute("goodsForm", goodsService.searchGoods(goodsForm));重复,应去掉一句。
(2)CartController.java中value = "initCart" value = "addCart" value = "delCart" value = "alipayConfirm" value = "replayAlipay"方法。其中value = "addCart"方法还得先获取goodsForm.setCommodityId(cartForm.getCommodityId());
(3)GoodsController.java涉及得比较多,就不一一细说,代码如下
@RequestMapping(value = "initGoods", method = RequestMethod.GET) public String initGoods(Model model, HttpSession session, GoodsForm goodsForm, Device device) throws UnsupportedEncodingException { log.info("商品列表初始化"); model.addAttribute("list", goodsService.getTypeList(goodsForm)); model.addAttribute("commodityType", goodsService.getType(goodsForm)); model.addAttribute("goodsForm", goodsForm); UVO uvo = (UVO)session.getAttribute("UVO"); if (uvo == null) { uvo = new UVO(); session.setAttribute("UVO", uvo); } CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); if(device.isNormal()) { return "shop/index"; } else { return "mobile/index"; } } @RequestMapping(value = "initGoodsDetail", method = RequestMethod.GET) public String initGoodsDetail(Model model, HttpSession session, GoodsForm goodsForm, Device device) { log.info("商品明细初始化"); model.addAttribute("commodityType", goodsService.getType(goodsForm)); UVO uvo = (UVO)session.getAttribute("UVO"); if (uvo == null) { uvo = new UVO(); session.setAttribute("UVO", uvo); } CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); model.addAttribute("goodsForm", goodsService.searchGoods(goodsForm)); if(device.isNormal()) { return "shop/goods/goodsDetail"; } else { return "mobile/goods/goodsDetail"; } } @RequestMapping(value = "selectGoods", method = RequestMethod.POST) public String selectGoods(Model model,HttpSession session,GoodsForm goodsForm,Device device){ log.info("检索相关商品"); model.addAttribute("commodityType", goodsService.getType(goodsForm)); Listlist=goodsService.searchGoodsListrelative(goodsForm); model.addAttribute("list",list); UVO uvo = (UVO)session.getAttribute("UVO"); if (uvo == null) { uvo = new UVO(); session.setAttribute("UVO", uvo); } CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); if(device.isNormal()) { return "shop/index"; } else { return "mobile/index"; } }}
(4)GuestController.java中value = "/" value = "initGuestLogin" value = "guestLogin" value = "initGuestRegister" value = "addGuest" value = "initEditGuest" value = "editGuest"方法
(5)SpecialController.java中value = "initSpecialAlipayComfirm" value = "specialAlipaySubmit" 方法
2. Form要添加内容:
private String commodityTypeId;
private String commodityTypeName;
3. SqlMap要改的有:
GoodsSqlMap.xml里的id="selectGoods"里的commodity.type as type改为commodity.type as commodityTypeId
4. topBar.html改为:
th:each="goodsInfo,status:${commodityType}"表示循环commodityType中的全部数据