index.htmlcss
<input type="hidden" name="commodityId" value="" th:value="${goodsForm.commodityId}" /> <div class="container main" th:each="typeInfo,sts:${commodityType}"> <div th:class="${typeInfo.css}" > <i class="yh"><span th:text="${typeInfo.count}">1F</span></i><span class="h4 yh" th:text="${typeInfo.commodityTypeName}">糧食</span> <a th:href="@{initGoods(commodityTypeId=${typeInfo.commodityTypeId})}">更多商品>></a> </div> <ul class="goodsList cf"> <li class="col-md-2 col-sm-4 col-xs-6" th:each="goodsInfo,status:${typeInfo.list}" > <div class="cont"> <a th:href="@{initGoodsDetail(commodityId=${goodsInfo.commodityId})}"><img th:src="@{showImage(pictureId=${goodsInfo.pictureId})}" alt="" style="height:168px;width:168px;" /></a> <h4 class="h5"><a href="#"><p class="title" th:text="${goodsInfo.commodityName}">品美知糖道阿膠薑湯260g</p></a></h4> <p class="num">庫存:<span th:text="${goodsInfo.stock}">15</span> 每<span th:text="${#strings.concat(goodsInfo.unit).concat(goodsInfo.specifications)}">袋15kg</span> </p> <p class="cf"> <span class="price yh">¥<span th:text="${goodsInfo.retailPrice}">15</span>元</span> <a th:href="@{addCart}" class="btnBuy" title="加入購物車"></a> </p> </div> </li> </ul> </div>
點擊"更多商品"跳轉到GoodsController.javahtml
@RequestMapping(value = "initGoods", method = RequestMethod.GET) public String initGoods(Model model, HttpSession session, GoodsForm goodsForm, Device device) throws UnsupportedEncodingException { log.info("商品列表初始化"); List<GoodsForm> commodityType = goodsService.getType(); model.addAttribute("commodityType", goodsService.getType()); if(goodsForm.getCommodityTypeId()==null) { goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); model.addAttribute("list", goodsService.getTypeList(goodsForm)); model.addAttribute("goodsForm", goodsForm); } else {model.addAttribute("goodsForm", goodsForm); model.addAttribute("list", goodsService.getTypeList(goodsForm)); } UVO uvo = (UVO)session.getAttribute("UVO"); if (uvo == null) { uvo = new UVO(); session.setAttribute("UVO", uvo); } model.addAttribute("orderTypeId", 1); CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); if(device.isNormal()) { return "shop/list"; } else { return "mobile/list"; } }
點擊圖片,跳轉到GoodsController.java 中 initGoodsDetail 方法java
@RequestMapping(value = "initGoodsDetail", method = RequestMethod.GET) public String initGoodsDetail(Model model, HttpSession session, GoodsForm goodsForm, Device device) { log.info("商品明細初始化"); model.addAttribute("commodityType", goodsService.getType()); 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("list", goodsService.searchGoodsListOder(goodsForm)); model.addAttribute("cartList", cartService.searchCartList(cartForm)); model.addAttribute("goodsForm", goodsService.searchGoods(goodsForm)); if(device.isNormal()) { return "shop/goods/details"; } else { return "mobile/goods/details"; } }