购物系统的购物车模块的问题
用户购买商品后传了一个这个商品的id,我用hql语句查询到这个商品的信息private Goods goods = new Goods();
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}
public List <Goods> BuyGoods(){
HttpServletRequest request = ServletActionContext.getRequest();
String goodsId = request.getParameter("id");
Session session = HibernateSessionFactory.getSession();
String hql = "from Goods as g where g.goodsid = ?";
Query query = session.createQuery(hql);
query.setString(0,goodsId);
List list = query.list();
ActionContext.getContext().getSession().put("shoppingGoods", list);
return list;
}
然后在action里将这个id取出做了修改数量的处理
HttpServletRequest request = ServletActionContext.getRequest();
String goodsId = request.getParameter("id"); //获取图书id
String number = request.getParameter("number"); //获取购买数量
int n = Integer.parseInt(number);
//System.out.println(n+"==============");
BuyGoodsDao buy =new BuyGoodsDao();
List <Goods> list = buy.BuyGoods();
for(Goods g : list){
int kuncun = g.getGoodsstock();
if(kuncun < n){
return Action.SUCCESS;
}else{
int i = kuncun-n;
try {
Session ss = HibernateSessionFactory.getSession();
g.setGoodsstock(i);
ss.beginTransaction();
ss.save(g);
ss.getTransaction().commit();
ss.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "hui";
我的思路可能不对,后面我不知道怎么把这个商品放到session里了,请大神给个好的思路,本人小白 --------------------编程问答-------------------- 除
补充:Java , Web 开发