package com.example.controller; import com.example.common.Result_; import com.example.entity.Cart; import com.example.service.CartService; import com.github.pagehelper.PageInfo; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; // 功能:购物车前端操作接口 @RestController @RequestMapping("/cart") public class CartController { @Resource private CartService cartService; // 新增购物车商品 @PostMapping("/add") public Result_ add(@RequestBody Cart cart) { cartService.add(cart); return Result_.success(); } // 根据ID删除购物车商品 @DeleteMapping("/delete/{id}") public Result_ deleteById(@PathVariable Integer id) { cartService.deleteById(id); return Result_.success(); } // 批量删除购物车商品 @DeleteMapping("/delete/batch") public Result_ deleteBatch(@RequestBody List ids) { cartService.deleteBatch(ids); return Result_.success(); } // 修改购物车商品信息 @PutMapping("/update") public Result_ updateById(@RequestBody Cart cart) { cartService.updateById(cart); return Result_.success(); } // 根据ID查询购物车商品 @GetMapping("/selectById/{id}") public Result_ selectById(@PathVariable Integer id) { Cart cart = cartService.selectById(id); return Result_.success(cart); } // 查询所有购物车商品(可带条件) @GetMapping("/selectAll") public Result_ selectAll(Cart cart ) { List list = cartService.selectAll(cart); return Result_.success(list); } // 分页查询购物车商品 @GetMapping("/selectPage") public Result_ selectPage(Cart cart, @RequestParam(defaultValue = "1") Integer pageNum, // 页码,默认为1 @RequestParam(defaultValue = "10") Integer pageSize) { // 每页大小,默认为10 PageInfo page = cartService.selectPage(cart, pageNum, pageSize); return Result_.success(page); } }