注: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>