Skip to content

查看购物车


ShoppingCartController

在 ShoppingCartController 中创建查看购物车的方法

java
/**
 * 查看购物车
 * @return
 */
@GetMapping("/list")
@ApiOperation("查看购物车")
public Result<List<ShoppingCart>> list(){
    return Result.success(shoppingCartService.showShoppingCart());
}

ShoppingCartService

在 ShoppingCartService 接口中声明查看购物车的方法

java
/**
 * 查看购物车
 * @return
 */
List<ShoppingCart> showShoppingCart();

ShoppingCartServiceImpl

在 ShoppingCartServiceImpl 中实现查看购物车的方法

java
/**
 * 查看购物车
 * @return
 */
public List<ShoppingCart> showShoppingCart() {
    return shoppingCartMapper.list(ShoppingCart.
                                    builder().
                                    userId(BaseContext.getCurrentId()).
                                    build());
}