package cn.sjzedu.controller;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.sjzedu.pojo.Cart;
import cn.sjzedu.pojo.Goods;
import cn.sjzedu.service.CartService;
import cn.sjzedu.service.GoodsService;
@Controller
@RequestMapping("/Cart")
public class CartController {
@Autowired
private GoodsService goodsService;
@Autowired
private CartService cartService;
//向购物车添加商品
@RequestMapping("/addgoods")
public String addgoods(Model model,HttpServletRequest req,HttpServletResponse rsp) throws Exception{
String goodsid = req.getParameter("goodsId");
String num = req.getParameter("num");
String url="";
if(num!=null&&num.length()>0){
int count = Integer.parseInt(num);
int id = Integer.parseInt(goodsid);
//如果购物车数量合理则加入购物车ﳵ
if(count>0){
cartService.insertGoods(id,count);
url="redirect:/showgoods.action";
}else{
//如果数量不合理则返回购物页面,并带着一个参数i
//为的是在购物界面根据不同问题显示不同的提示语句
url = "redirect:/showgoods.action?i=1";
}
}else{
//当购物车没有填写任何数据时,返回参数2
url = "redirect:/showgoods.action?i=2";
}
return url;
}
//ͨ通过id删除购物车商品
@RequestMapping("/deleteCart")
public String deletecart(HttpServletRequest req,HttpServletResponse rsp) throws Exception{
String cartid = req.getParameter("id");
int id = Integer.parseInt(cartid);
int res = cartService.deleteCartById(id);
String url = "";
if(res>0){
url = "redirect:/Account/account.action";
}
return url;
}
}
最近下载更多
15342201772 LV9
2024年11月12日
Xppasdf LV3
2024年10月29日
taoshen95 LV16
2024年3月22日
gecongkai LV8
2023年6月22日
yzshabzbbdvw LV4
2023年4月15日
malike LV3
2022年12月14日
lsglsg9 LV23
2022年11月26日
微信网友_6200823191523328 LV3
2022年11月11日
admin0108 LV9
2022年10月12日
1020132795 LV5
2022年9月25日
最近浏览更多
vincemokea LV9
4月24日
xiaoaitx LV8
1月1日
hcghhh
2024年12月28日
暂无贡献等级
微信网友_7310057461567488
2024年12月24日
暂无贡献等级
三秋桂子 LV1
2024年12月22日
Ella0902
2024年12月18日
暂无贡献等级
n1234560090
2024年12月11日
暂无贡献等级
sjwc88 LV4
2024年12月4日
Xppasdf LV3
2024年10月29日
zouzou123 LV3
2024年10月18日

