1.添加购物车
Controller层
@RequestMapping("add.do")
@ResponseBody
public ServerResponse<CartVo> add(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.add(user.getId(), productId, count);
}
Service层
public ServerResponse<CartVo> add(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){
//这个产品不在这个购物车里,需要新增一个这个产品的记录