在写Mybatis+springboot项目时,调用某mapper接口发生报错
### The error occurred while setting parameters ### SQL: insert into imooc_mall_cart Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
SQL后半句也没显示出来,而且near也没有定位到,搜索了很多帖子之后,找到一篇13年的帖子有类似情况,楼主说自己传了空的循环体进去导致insert 空,所以报了这个error,我觉得有道理,找到调用mapper的接口发现传参疏忽,把一个空值传进去了
validProduct(productId,count);
Cart cart = cartMapper.selectCartByUserIDAndProductID(userId, productId);
if (cart==null) {
//该商品之前不在购物车
Cart newCart = new Cart();
newCart.setUserId(userId);
newCart.setProductId(productId);
newCart.setQuantity(count);
newCart.setSelected(Constant.Cart.SELECTED);
cartMapper.insertSelective(newCart);//这里应该传newCart,结果我把cart传进去了
}
找到问题所在,现已解决。



