从零到企业级SSM电商项目实战教程(三十三)更新,删除购物车商品功能开发

CartController.java

@RequestMapping("update.do")
@ResponseBody
public ServerResponse update(HttpSession session, Integer count, Integer productId) {
    User user = (User) session.getAttribute(Const.CURRENT_USER);
    if (user == null) {
        return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
    }
    return iCartService.update(user.getId(), productId, count);
}

@RequestMapping("delete_product.do")
@ResponseBody
public ServerResponse deleteProduct(HttpSession session, String productIds) {
    User user = (User) session.getAttribute(Const.CURRENT_USER);
    if (user == null) {
        return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
    }
    return iCartService.deleteProduct(user.getId(), productIds);
}

ICartService.java

ServerResponse update(Integer userId,Integer productId,Integer count);

ServerResponse deleteProduct(Integer userId,String productIds);

CartServiceImpl.java

public ServerResponse update(Integer userId,Integer productId,Integer count){
    if(productId == null || count == null){
        return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),ResponseCode.ILLEGAL_ARGUMENT.getDesc());
    }
    Cart cart = cartMapper.selectCartByUserIdProductId(userId,productId);
    if(cart != null){
        cart.setQuantity(count);
    }
    cartMapper.updateByPrimaryKeySelective(cart);
    CartVo cartVo = this.getCartVoLimit(userId);
    return ServerResponse.createBySuccess(cartVo);
}

public ServerResponse deleteProduct(Integer userId,String productIds){
    List productList = Splitter.on(",").splitToList(productIds);
    if(CollectionUtils.isEmpty(productList)){
        return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),ResponseCode.ILLEGAL_ARGUMENT.getDesc());
    }
    cartMapper.deleteByUserIdProductIds(userId,productList);
    CartVo cartVo = this.getCartVoLimit(userId);
    return ServerResponse.createBySuccess(cartVo);
}

CartMapper.java

int deleteByUserIdProductIds(@Param("userId") Integer userId,@Param("productIdList")List productIdList);

CartMapper.xml


  delete from mmall_cart
  where user_id = #{userId}
  
    and product_id in
    
      #{item}
    
  

本站所有文章均由网友分享,仅用于参考学习用,请勿直接转载,如有侵权,请联系网站客服删除相关文章。若由于商用引起版权纠纷,一切责任均由使用者承担
极客文库 » 从零到企业级SSM电商项目实战教程(三十三)更新,删除购物车商品功能开发

欢迎加入「极客文库」,成为原创作者从这里开始!

立即加入 了解更多