コード例 #1
0
  // 导出商品
  public void load(String content) {
    if (content == null || content.equals("0")) {
      return;
    }
    String[] pcs = content.split(";");
    for (int i = 0; i < pcs.length; i++) {
      String pc = pcs[i];
      String[] strs = pc.split(",");
      int id = Integer.parseInt(strs[0]);
      int qty = Integer.parseInt(strs[1]);
      boolean buy = Boolean.parseBoolean(strs[2]);

      try {
        Product pro = productDAO.findById(id);
        CartItem item = new CartItem();
        item.setProduct(pro);
        item.setQty(qty);
        item.setBuy(buy);
        store.add(item);

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
コード例 #2
0
 // 恢复商品
 public void recovery(int pid) throws Exception {
   for (CartItem item : store) {
     if (item.getProduct().getId() == pid) {
       item.setBuy(true);
     }
   }
 }
コード例 #3
0
 // 删除商品
 public void delete(int pid) throws Exception {
   for (CartItem item : store) {
     if (item.getProduct().getId() == pid) {
       item.setBuy(false);
     }
   }
   // CookieUtil.addCookie(Constant.CART, cart.store(), response);
 }