日期:2014-05-16 浏览次数:20946 次
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;
}
ttpServletRequest 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);
&n