1.描述:用户注册成功账号并登录系统之后,通过主页展示的报刊或按报刊类别找到所需购买的报刊,通过点击报刊图片,打开报刊详细信息界面,浏览报刊的基本信息,然后若用户想购买报刊,输入购买数量,点击购买按钮,则可完成加入购物车操作。
2.如图5-4所示:
public String addToCart() { HttpServletRequest req=ServletActionContext.getRequest(); int goodsId=Integer.parseInt(req.getParameter("goodsId")); int quantity=Integer.parseInt(req.getParameter("quantity")); TGoods goods=goodsDAO.findById(goodsId); TOrderItem orderItem=new TOrderItem(); orderItem.setGoods(goods); orderItem.setGoodsQuantity(quantity); Map session= ServletActionContext.getContext().getSession(); Cart cart = (Cart)session.get("cart"); cart.addGoods(goodsId, orderItem); session.put("cart",cart); this.setPath("myCart.action"); return "succeed"; }
1.描述:在用户购买的报刊先存放在购物车中,点击菜单中的“我的购物车”,即可查看用户当前购物车中的内容,用户可以实现报刊数量的增加、减少,删除某一件报刊和继续添加报刊及清空购物车操作。
2.程序效果如图5-5所示。
public String orderSubmit() { HttpServletRequest req=ServletActionContext.getRequest(); Map session= ServletActionContext.getContext().getSession(); Cart cart = (Cart)session.get("cart"); TUser user11=(TUser)session.get("user"); TUser user=userDAO.findById(user11.getUserId()); int dingdanzongjia=0; String userLeixing=user.getUserLeixing(); if(userLeixing.equals("普通会员")) { dingdanzongjia=(int)((cart.getTotalPrice() * 1.0)); } if(user.getUserJine()<dingdanzongjia) { this.setMessage("您的账户余额不足,请先联系管理员充值后付款"); this.setPath("qiantai/default.jsp"); return "succeed"; } TOrder order=new TOrder(); order.setOrderBianhao(new SimpleDateFormat("yyyyMMddhhmmss").format(new Date())); order.setOrderDate(newSimpleDateFormat("yyyy-MM-ddhh:mm:ss").format (new Date())); order.setOrderZhuangtai("待受理");//未受理 order.setOrderUserId(user.getUserId()); order.setOrderJine(dingdanzongjia); order.setOdderSonghuodizhi(req.getParameter("odderSonghuodizhi")); orderDAO.save(order); for (Iterator it = cart.getItems().values().iterator(); it.hasNext();) { TOrderItem orderItem = (TOrderItem) it.next(); orderItem.setOrderId(order.getOrderId()); orderItem.setGoodsId(orderItem.getGoods().getGoodsId()); orderItemDAO.save(orderItem); } cart.getItems().clear(); session.put("cart", cart); Map request=(Map)ServletActionContext.getContext().get("request"); request.put("order", order); user.setUserJine(user.getUserJine()-dingdanzongjia); userDAO.attachDirty(user); return ActionSupport.SUCCESS; }
开发环境
开发工具:idea、Navicat
数据库:MySQL8.0
环境配置:jdk1.8 、Tomcat8.5
开发人员:IT012201