以下均为 controller层代码显示
1、查询全部
@RestController
@RequestMapping("/goods")
@CrossOrigin
public class GoodsController {
@Autowired
private GoodsService goodsService;
//查询商品列表
@GetMapping
public List<Goods> selectAll(){
List<Goods> selectAll = goodsService.selectGoodsAll();
return selectAll;
}
- Postman测试结果
2、根据id查询详情
//商品详情
@GetMapping("{id}")
public Goods selectById(@PathVariable("id") String id){
Goods selectById = goodsService.selectGoodsById(id);
return selectById;
}
- 测试结果
需要传入参数id时,直接在url地址后写id值即可,入图片中的 /2
3 insert 添加
//商品添加
@PostMapping
public void insertGoods(@RequestBody Goods goods){
goodsService.insertGoods(goods);
}
- postman测试
测试为post请求,选择Body–>raw–>JSON,输入要添加的字符串,以json形式
- 修改商品信息
//商品修改
@PutMapping
public void updategoods(@RequestBody Goods goods){
goodsService.updateGoods(goods);
}
- Postman测试
与插入数据类似,把post换成put请求,修改商品的信息内容,send
- 根据id删除
//商品下架
@DeleteMapping("{id}")
public void delectgoods(@PathVariable("id") String id){
goodsService.delectGoods(id);
}
- postman测试
与查看详情类似,delete请求,在url地址后输入要删除的id