list.html
html
<div class="btn-group btn-group-sm btn-sort col-sm-6" role="group" > <span th:if="${#strings.isEmpty(goodsForm.commodityName)}"><!-- 登陸上 --> <a th:href="@{initGoods(commodityTypeId=${goodsForm.commodityTypeId})}" th:class="${orderTypeId}==1?'btn btn-default btn-danger':'btn btn-default'"> 默 認 </a> <a th:href="@{initGoodsByPopularDesc(commodityTypeId=${goodsForm.commodityTypeId})}" th:class="${orderTypeId}==3?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}!=2"> 人 氣<i></i> </a> <a th:href="@{initGoodsByPopular(commodityTypeId=${goodsForm.commodityTypeId})}" th:class="${orderTypeId}==2?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}==2"> 人 氣<i class="up"></i> </a> <a th:href="@{initGoodsByPriceDesc(commodityTypeId=${goodsForm.commodityTypeId})}" th:class="${orderTypeId}==5?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}!=4"> 價 格<i></i> </a> <a th:href="@{initGoodsByPrice(commodityTypeId=${goodsForm.commodityTypeId})}" th:class="${orderTypeId}==4?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}==4"> 價 格<i class="up"></i> </a> </span> <span th:if="${not #strings.isEmpty(goodsForm.commodityName)}"><!-- 不登陸 --> <a th:href="@{selectGoods1(commodityName=${goodsForm.commodityName})}" th:class="${orderTypeId}==1?'btn btn-default btn-danger':'btn btn-default'"> 默 認 </a> <a th:href="@{selectGoodsByPopularDesc(commodityName=${goodsForm.commodityName})}" th:class="${orderTypeId}==3?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}!=2"> 人 氣<i></i> </a> <a th:href="@{selectGoodsByPopular(commodityName=${goodsForm.commodityName})}" th:class="${orderTypeId}==2?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}==2"> 人 氣<i class="up"></i> </a> <a th:href="@{selectGoodsByPriceDesc(commodityName=${goodsForm.commodityName})}" th:class="${orderTypeId}==5?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}!=4"> 價 格<i></i> </a> <a th:href="@{selectGoodsByPrice(commodityName=${goodsForm.commodityName})}" th:class="${orderTypeId}==4?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}==4"> 價 格<i class="up"></i> </a> </span> </div>
GoodsController.javajava
@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"; } } @RequestMapping(value = "initGoodsByPopularDesc", method = RequestMethod.GET) public String initGoodsByPopularDesc(Model model, HttpSession session, GoodsForm goodsForm, Device device) { 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("list", goodsService.searchGoodsListByPopularDesc(goodsForm)); model.addAttribute("orderTypeId", 2); CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); if(device.isNormal()) { return "shop/list"; } else { return "mobile/list"; } } @RequestMapping(value = "initGoodsByPopular", method = RequestMethod.GET) public String initGoodsByPopular(Model model, HttpSession session, GoodsForm goodsForm, Device device) { 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("list", goodsService.searchGoodsListByPopular(goodsForm)); model.addAttribute("orderTypeId", 3); CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); if(device.isNormal()) { return "shop/list"; } else { return "mobile/list"; } } @RequestMapping(value = "initGoodsByPriceDesc", method = RequestMethod.GET) public String initGoodsByPriceDesc(Model model, HttpSession session, GoodsForm goodsForm, Device device) { 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("list", goodsService.searchGoodsListByPriceDesc(goodsForm)); model.addAttribute("orderTypeId", 4); CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); if(device.isNormal()) { return "shop/list"; } else { return "mobile/list"; } } @RequestMapping(value = "initGoodsByPrice", method = RequestMethod.GET) public String initGoodsByPrice(Model model, HttpSession session, GoodsForm goodsForm, Device device) { 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("list", goodsService.searchGoodsListByPrice(goodsForm)); model.addAttribute("orderTypeId", 5); CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); if(device.isNormal()) { return "shop/list"; } else { return "mobile/list"; } }