//5.显示购物车
public List showMyCart() {
String hql="from Goods where goodsId in";
//使用迭代器从HashMap中取出货物Id
Iterator it=hm.keySet().iterator();
String sub="(";
while(it.hasNext()){
//取出goodsId
String goodsId=(String)it.next();
//判断goodsId是不是最后一个
if(it.hasNext()){
sub+=goodsId+",";
}else {
sub+=goodsId+")";
}
}
hql+=sub;
System.out.println(hql);
List list=this.executeQuery(hql, null);

System.out.println("商品名:"+((Goods) list.get(0)).getGoodName());
//把总价清空一下
this.allPrice=0.0f;
for(int i=0;i<list.size();i++){
this.allPrice=this.allPrice+(((Goods) list.get(i)).getGoodsPrice())*this.getGoodsNumById(((Goods) list.get(i)).getGoodsId()+"");
}
 return list;
}//查询
public List executeQuery(String hql, Object[] parameters) {
Query query=this.sessionFactory.getCurrentSession().createQuer(hql);
//给?号注入值
if(parameters!=null && parameters.length>0){
for(int i=0;i<parameters.length;i++){
query.setParameter(i, parameters[i]);
}
}

return query.list();

}
数据库中是有对应数据的就是查不出来。