标签:
1.index.heml页面
<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><!-- 利用i循环进行1F到8F的循环 -->
<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})}" 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>
按照商品类型对商品进行分类检索并显示
2.商品列表按人气和价格的升序降序排列的功能实现
list.html页面
<div class="btn-group btn-group-sm btn-sort col-sm-6" role="group" >
<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>
</div>
GoodsController.java
//以人气的升序进行排列
@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";
}
}
标签:
原文地址:http://my.oschina.net/u/2411770/blog/490831