购物车内物品数量控制问题

会飞的蝌蚪 发布于 2013/06/16 11:07
阅读 80
收藏 0

点击购买 把物品放到map内 再放入seaaion内  当再次点击购买时  怎么让数量增加

 Books books = BeanUtils.populate(Books.class,
    (Map) request.getParameterMap());
  Map<String, Books> map = (Map<String, Books>) request
    .getAttribute("car");

  if (map == null) {
   map = new HashMap<String, Books>();
   request.getSession().setAttribute("car", map);
  }
  if (map.containsKey(books.getId())) {
   books = map.get(books.getId());
   books.setAmt(books.getAmt()+1);
   
  // System.out.println(books.getAmt());
  } else {
   books.setAmt(1);
   map.put(books.getId(), books);
  }

 

 

 

 

System.out.println("---------------------------");
  Map<String, Books> car = (Map<String, Books>) request.getSession()
    .getAttribute("car");
  

  Iterator<Map.Entry<String, Books>> it = car.entrySet().iterator();
  while (it.hasNext()) {
   Books boo = it.next().getValue();
   System.out.println(">>>" + boo);
  }

 

点击多次购买后    后台输出的记录图书数量的amt一直是1

 

加载中
返回顶部
顶部