public Trolley confirmIsExist(Trolley trolley) { Trolley t = null; try { t = (Trolley)this.qRunner.query("select * from trolley where uid = ? and gid = ? and orders_number is null", new BeanHandler<Trolley>(Trolley.class), new Object[]{trolley.getUid(), trolley.getGid()}); } catch (SQLException var4) { var4.printStackTrace(); } return t; }
时间: 2024-02-14 14:14:17 浏览: 31
这段代码是一个方法,方法名为`confirmIsExist`,返回一个`Trolley`对象。该方法的目的是查询购物车中某个商品是否存在于数据库中,如果存在则返回该商品的信息,否则返回`null`。方法中使用了`Apache`的`DbUtils`库,通过`query`方法执行一条`SQL`语句,查询符合条件的数据,并使用`BeanHandler`将查询结果映射成`Trolley`类的实例。其中`?`是占位符,被`new Object[]{trolley.getUid(), trolley.getGid()}`所代替。如果查询过程中出现`SQLException`异常,则打印异常信息。最后返回查询结果。
相关问题
public List<Trolley> findAllTrolley(User user) { List<Trolley> trolleys = null; try { trolleys = (List<Trolley>)this.qRunner.query("select * from trolley where uid = ? and orders_number is null", new BeanListHandler<Trolley>(Trolley.class), new Object[]{user.getUid()}); } catch (SQLException var4) { var4.printStackTrace(); } return trolleys; }
这段代码是一个方法,方法名为`findAllTrolley`,返回一个`List<Trolley>`类型的购物车商品列表。该方法的目的是查询购物车中某个用户的所有商品信息,查询的条件是订单号为`null`。方法中同样使用了`Apache`的`DbUtils`库,通过`query`方法执行一条`SQL`语句,查询符合条件的所有记录,并使用`BeanListHandler`将查询结果映射成`Trolley`类的实例列表。其中`?`是占位符,被`new Object[]{user.getUid()}`所代替。如果查询过程中出现`SQLException`异常,则打印异常信息。最后返回查询结果。
public void updateTrolley(Trolley trolley) { try { this.qRunner.update("update trolley set number = ? where tid = ?", new Object[]{trolley.getNumber(), trolley.getTid()}); } catch (SQLException var3) { var3.printStackTrace(); } }
这段代码是一个方法,方法名为`updateTrolley`,没有返回值。该方法的目的是更新购物车中某个商品的数量,将商品信息更新到数据库中。方法中同样使用了`Apache`的`DbUtils`库,通过`update`方法执行一条`SQL`语句,更新`Trolley`表中符合条件的记录,其中`?`是占位符,被`new Object[]{trolley.getNumber(), trolley.getTid()}`所代替。如果更新过程中出现`SQLException`异常,则打印异常信息。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<c:set var="sum_price" value="0"></c:set> <c:set var="goods_count" value="0"></c:set> <c:set var="tids" value="#"></c:set> <c:forEach items="${trolleys }" var="trolley"> <c:set var="tids" value="${tids }#${trolley.tid }"></c:set>
${trolley.goods.gname } ${trolley.goods.color } ${trolley.goods.price }元 - <input type="text" value="${trolley.number }" id="num"> <c:set var="goods_count" value="${goods_count + trolley.number }"></c:set> + <c:set var="sum_price" value="${sum_price + trolley.goods.price * trolley.number }"></c:set> ${trolley.goods.price * trolley.number }元 删除 </c:forEach>
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)