根据ID删除购物车中对应的数据
private ShoppingDTO shopping;
private Map<String,Object> session=ServletActionContext.getContext().getSession();
private String successok;
private List<ShoppingDTO> books;
private Map<String, List> shoppingcar;
public String Shopping(){
shopping = shoppingIBIZimp.getShopping(shopping);// 实例化这个对象并将页面输入的数据添加到对应的字段
shopping.setSun((double)shopping.getCount()*shopping.getPrice());//总金额
shoppingcar=(Map)session.get("shoppingcar");
if(shoppingcar==null){
shoppingcar=new HashMap<String, List>();
session.put("shoppingcar", shoppingcar);
}
books= shoppingcar.get("books");
if(books==null){
books=new ArrayList<ShoppingDTO>();
shoppingcar.put("books", books);
}
for (int i = 0; i < books.size(); i++) {
if(books.get(i).getId()==shopping.getId()){
books.get(i).setCount(books.get(i).getCount()+shopping.getCount());
books.get(i).setSun((books.get(i).getCount()*books.get(i).getPrice()));
successok = "成功";
ServletActionContext.getRequest().getSession().setAttribute("successok", successok);
return Action.SUCCESS;
}
}
books.add(shopping);
JSP页面:
<body>
<s:iterator value="#session.shoppingcar.books" var="book">
商品名称:<s:property value="#book.name"/>,
商品颜色:<s:property value="#book.colors"/>
商品单价:<s:property value="#book.price"/>,
订购数量:<s:property value="#book.count"/>,
订购总价:<s:property value="#book.sun"/>,
<a href="clearShoppingid.action?clearid=${book.id}">删除</a>
<br/>
</s:iterator>
</body>
添加是可以的 现在需要的就是 将session 里面通过 ID删除session里面的数据 啊Action 里面怎么实现
------解决方案--------------------
shoppingcar=(Map<String, List>)session.get("shoppingcar");
books= (List<ShoppingDTO>)shoppingcar.get("books");