小购物车- ヅEpisode`√ - JavaEye技术网站
	public ActionForward CartItmeAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DynaActionForm dynaFrom = (DynaActionForm) form;
		// 食物的dbo
		Food f = (Food) dynaFrom.get("Food");
		FoodBiz foodbiz = new FoodBiz();
		// 购物车Map
		Food food = foodbiz.getFoodByFoodId(f.getFoodId());
		HttpSession session = request.getSession();
		Map cartMap = (Map) session.getAttribute("cartMap");
	
		// 如果没有创建购物车 就创建购物车
		if (cartMap == null) {
			cartMap = new HashMap();
			// 将购物车存到Session
			session.setAttribute("cartMap", cartMap);
		}
		// 获得购物车对象
		CartItemEntity cartentity = (CartItemEntity) cartMap.get(food
				.getFoodId());
		if (cartentity != null) {
			cartentity.setNum(cartentity.getNum() + 1);
		
		} else {
		
			cartMap.put(food.getFoodId(), new CartItemEntity(food, 1));
			
		}
		//迭代存到List
		Collection coll = cartMap.values();
		List list = new ArrayList();
		for (Iterator iter = coll.iterator(); iter.hasNext();) {
			CartItemEntity element = (CartItemEntity) iter.next();
			
			list.add(element);
		}
		
		request.setAttribute("cartList", list);
		
		return mapping.findForward("cartItem");
	}
	

?

郑重声明:资讯 【小购物车- ヅEpisode`√ - JavaEye技术网站】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——