列表中的"默認"、"人氣"、"價格"實現的相關知識

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'">&nbsp;默&nbsp;認&nbsp;</a>
	<a th:href="@{initGoodsByPopularDesc(commodityTypeId=${goodsForm.commodityTypeId})}" th:class="${orderTypeId}==3?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}!=2">&nbsp;人&nbsp;氣<i></i>&nbsp;</a>
	<a th:href="@{initGoodsByPopular(commodityTypeId=${goodsForm.commodityTypeId})}" th:class="${orderTypeId}==2?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}==2">&nbsp;人&nbsp;氣<i class="up"></i>&nbsp;</a>
	 <a th:href="@{initGoodsByPriceDesc(commodityTypeId=${goodsForm.commodityTypeId})}" th:class="${orderTypeId}==5?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}!=4">&nbsp;價&nbsp;格<i></i>&nbsp;</a>
	<a th:href="@{initGoodsByPrice(commodityTypeId=${goodsForm.commodityTypeId})}" th:class="${orderTypeId}==4?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}==4">&nbsp;價&nbsp;格<i class="up"></i>&nbsp;</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'">&nbsp;默&nbsp;認&nbsp;</a>
	  <a th:href="@{selectGoodsByPopularDesc(commodityName=${goodsForm.commodityName})}" th:class="${orderTypeId}==3?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}!=2">&nbsp;人&nbsp;氣<i></i>&nbsp;</a>
	 <a th:href="@{selectGoodsByPopular(commodityName=${goodsForm.commodityName})}" th:class="${orderTypeId}==2?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}==2">&nbsp;人&nbsp;氣<i class="up"></i>&nbsp;</a>
	 <a th:href="@{selectGoodsByPriceDesc(commodityName=${goodsForm.commodityName})}" th:class="${orderTypeId}==5?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}!=4">&nbsp;價&nbsp;格<i></i>&nbsp;</a>
	<a th:href="@{selectGoodsByPrice(commodityName=${goodsForm.commodityName})}" th:class="${orderTypeId}==4?'btn btn-default btn-danger':'btn btn-default'" th:if="${orderTypeId}==4">&nbsp;價&nbsp;格<i class="up"></i>&nbsp;</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";
    	}
    }
相關文章
相關標籤/搜索