1.接口:
ShoppingCartMapper :
@Repository
public interface ShoppingCartMapper extends GeneralDAO<ShoppingCart> {
public List<ShoppingCartVO> selectShopcartByUserId(int userId);
public int updateCartnumByCartId(@Param("cartId") int cartId,
@Param("cartNum") int cartNum);//数据库要进行两个及以上的操作,需要通过@Param指定
}
2.映射配置
<update id="updateCartnumByCartId">
update shopping_cart set cart_num=#{cartNum} where cart_id=#{cartId}
</update>
3.业务层
ShoppingCartService:
public ResultVO updateCartNum(int cartId,int cartNum);
ShoppingCartServiceImpl:
@Override
public ResultVO updateCartNum(int cartId, int cartNum) {
int i = shoppingCartMapper.updateCartnumByCartId(cartId, cartNum);
if (i>0){
return new ResultVO(ResStatus.OK,"update success",null);
}else {
return new ResultVO(ResStatus.NO,"update fail",null);
}
}
4.控制层实现
@PutMapping("/update/{cid}/{cnum}")
public ResultVO updateNum(@PathVariable("cid") Integer cartId,
@PathVariable("cnum") Integer cartNum,
@RequestHeader("token") String token){
ResultVO resultVO = shoppingCartService.updateCartNum(cartId, cartNum);
return resultVO;
}