请大神帮忙看下这句代码什么意思啊? Stock stock = (Stock)stockList.get(0); 代码见下:public void AddBuyInfo(BuyInfo buyInfo) throws Exception { Session s = null; Transaction tx = null; try { s = Hibe

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 20:05:03
请大神帮忙看下这句代码什么意思啊?Stockstock=(Stock)stockList.get(0);代码见下:publicvoidAddBuyInfo(BuyInfobuyInfo)throwsE

请大神帮忙看下这句代码什么意思啊? Stock stock = (Stock)stockList.get(0); 代码见下:public void AddBuyInfo(BuyInfo buyInfo) throws Exception { Session s = null; Transaction tx = null; try { s = Hibe
请大神帮忙看下这句代码什么意思啊? Stock stock = (Stock)stockList.get(0); 代码见下:
public void AddBuyInfo(BuyInfo buyInfo) throws Exception {
Session s = null;
Transaction tx = null;
try {
s = HibernateUtil.getSession();
tx = s.beginTransaction();
/*根据商品编号获取到商品库存对象*/
int productId = buyInfo.getProduct().getProductId();
String hql = "From Stock stock where stock.product.productId=" + productId;
Query q = s.createQuery(hql);
/*计算当前显示页码的开始记录*/
List stockList = q.list();
Stock stock = (Stock)stockList.get(0);
/*更新商品库存信息*/
stock.setStockCount(stock.getStockCount() + buyInfo.getCount());
/*更新商品价格*/
stock.setStockprice(buyInfo.getPrice());
/*登记进货信息*/
s.merge(buyInfo);
/*更新库存信息*/
s.merge(stock);
tx.commit();
} catch (HibernateException e) {
if(tx != null)
tx.rollback();
throw e;
} finally {
HibernateUtil.closeSession();
}
}

请大神帮忙看下这句代码什么意思啊? Stock stock = (Stock)stockList.get(0); 代码见下:public void AddBuyInfo(BuyInfo buyInfo) throws Exception { Session s = null; Transaction tx = null; try { s = Hibe
Stock明显是一个JavaBean.里面是什么我就不知道了.
然后stockList是一个集合,那句代码就是获取这个集合里面的第一个元素.然后把这个获取到的对象强制类型转换成Stock,再赋值给stock变量.其中(class)这样的写法就是强制类型转换了,括号里面的就是需要转换的类型了.