注:javascript
点击"结算"-controller.java中alipayConfirm方法,return "shop/cart/cart-2";-cart-2静态页面显示java
超连接方式跳转-controller.java的方法要把"POST"改成"GET"数据库
若是出现"GET"方法错误,看看是否是静态连接跳转,若是是能够尝试把controller.java中的方法改成 "GET"方法。session
在购物车列表中,显示数据库中的数据,和删除功能,还有加入购物车的件数app
<div th:each="cartsInfo,status:${cartList}">//全部 方法要放在遍历方法的div层内this
<tr>spa
<td class="chk"><input type="checkbox"/></td>orm
<td> ip
<div class="cont cf">ci
<a href="#"><img alt="" class="pic" th:src="@{showImage(pictureId=${cartsInfo.pictureId})}" /></a>
<h3><span th:text="${cartsInfo.commodityName}"></span></h3>
<p>品牌:<span th:text="${cartsInfo.brandName}"></span></p>
<p>经销商:<span th:text="${cartsInfo.supplierName}"></span></p>
<p>规格:每<span th:text="${#strings.concat(cartsInfo.unit).concat(cartsInfo.specifications)}"></span></p>
<p>零售价:<span th:text="${cartsInfo.retailPrice}"></span>元</p>
<p>购买日期:<span th:text="${cartsInfo.updateTime}"></span></p>
</div>
</td>
<td><p class="price yh">¥19.6</p></td>
<td>
<div class="chooseAmount">
<a href="javascript:;" onclick="subNum();"></a>
<input type="text" name="count" id="count" class="fl inp-t" value="1"/>
<a href="javascript:;" onclick="addNum();"></a>
</div>
</td>
<td><p class="price yh">¥19.6</p></td>
<td> <p>
<a class="button" th:href="@{delCart(cartId=${cartsInfo.cartId},count=${cartsInfo.count},commodityId=${cartsInfo.commodityId})}"><span>删除</span></a>
</p>
</td>
</tr>
</div>
cartController.java 删除购物车中的商品
@RequestMapping(value = "delCart", method = RequestMethod.GET)
public String executeDelCart(Model model, HttpSession session, CartForm cartForm, Device device) throws SQLException {
log.info("删除购物车");
UVO uvo = (UVO)session.getAttribute("UVO");
if (uvo == null || StringUtils.isEmpty(uvo.getGuestId())) {
return "redirect:/initGuestLogin";
}
cartForm.setUpdateUser(uvo.getGuestName());
Date date = new Date();
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cartForm.setUpdateTime(dateformat.format(date));
boolean result = cartService.delCart(cartForm);
if (!result) {
throw new SQLException("删除购物车失败!");
}
cartForm.setGuestId(uvo.getGuestId());
GoodsForm goodsForm=new GoodsForm();
// goodsForm.setType("粮食");
// model.addAttribute("goodsForm", goodsForm);
List<GoodsForm> commodityType = goodsService.getType();
goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId());
model.addAttribute("goodsForm", goodsForm);
model.addAttribute("commodityType", commodityType);
model.addAttribute("cartList", cartService.searchCartList(cartForm));
model.addAttribute("list", cartService.searchAlipayHistoryList(cartForm));
if(device.isNormal()) {
return "shop/cart/cart-1";
} else {
return "mobile/cart/cartList";
}
}
全选
function checkAll(obj, name) {
var el = document.getElementsByTagName('input');
var len = el.length;
for (var key in el) {
if (el[key].name == name) {
if(obj.checked == true) {
el[key].checked = true;
} else {
el[key].checked = false;
}
}
}
}
<tr>
<th class="wp7_5"><input type="checkbox" onclick="checkAll(this,'checkTest')" class="vm" /> 全选</th>
<th class="wp40">商品详情</th>
<th class="wp15">单价</th>
<th class="wp15">数量</th>
<th class="wp15">小计</th>
<th class="wp7_5">操做</th>
</tr>
购物车商品的数量
<td>
<div class="chooseAmount">
<a href="javascript:void(0);"
th:onclick="${#strings.concat('subNum(').concat(cartsInfo.commodityId).concat(')')}"></a>
<input th:id="${cartsInfo.commodityId}" type="text" class="fl inp-t" value="1" />
<a href="javascript:void(0);"
th:onclick="${#strings.concat('addNum(').concat(cartsInfo.commodityId).concat(')')}"></a>
</div>
</td>