You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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<Integer> 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<Cart> 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<Cart> page = cartService.selectPage(cart, pageNum, pageSize);
return Result_.success(page);
}
}