效果
Map cart = new HashMap();
cart.put(new GoodsVO(1001,"苹果",100),5);
cart.put(new GoodsVO(1002,"桔子",300),3);
cart.put(new GoodsVO(1003,"香蕉",150),3);
request.getSession().setAttribute("cat",cart);
前端页面
${item.key.name}
-
+
//购买商品数量减1
$(".subSpan").click(function () {
let subSpanId = $(this).attr("id");
let id = subSpanId.substring(7);
let amount = $("#amountInput" + id).val();
if (amount - 1 stock) {
alert("所购商品数量不能大于库存");
return;
}
$("#amountInput" + id).val(amount + 1);
})