ALTER TABLE shopping_cart ADD INDEX c_all(cart_id,product_id,sku_id,user_id,cart_num,cart_time,product_price,sku_props) ALTER TABLE product_img ADD INDEX itemidx (item_id)
SELECT c.cart_id ,c.product_id ,c.sku_id, c.user_id,c.cart_num ,c.cart_time,c.product_price, c.sku_props,s.original_price,s.sell_price,s.sku_name, p.product_name,i.url,s.stock FROM shopping_cart c INNER JOIN product p INNER JOIN product_img i INNER JOIN product_sku s ON s.sku_id=c.sku_id AND p.product_id=c.product_id AND i.item_id=c.product_id WHERE i.is_main=1 AND c.cart_id IN(76,77)
动态sql的编写
Sercive层实现类
@Override public ResultVo getshopcartsbyCartids(String cids) {//从前端传入到后端的是字符串, // 在service层进行拼接 String[] arr = cids.split(","); ListcartIds=new ArrayList<>(); for (String s : arr) { cartIds.add(Integer.parseInt(s)); } List shoppingCartList = shoppingCartMapper.selectShoppingCartByICartIds(cartIds); return new ResultVo(ResStatus.OK,"success",shoppingCartList); }