创建商品微服务,实现对品牌表的增删改查功能。具体包括
(1)查询全部列表数据
(2)根据ID查询实体数据
(3)增加
(4)修改
(5)删除
(6)条件查询
(7)分页查询
(8)分页+条件查询
(9)公共异常处理

写Dao层要用到changgou-service-goods-api工程下的pojo,引入依赖:


查询全部列表数据
package com.changgou.controller;
import com.changgou.service.BrandService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.Brand;
import tk.mybatis.spring.annotation.MapperScan;
import java.util.List;
@RestController
@RequestMapping(value = "/brand")
@CrossOrigin//跨域
@MapperScan(basePackages = {"com.changgou.dao"})//开启通用Mapper的包扫描
public class BrandController {
@Autowired
private BrandService brandService;
@GetMapping
public Result<List<Brand>> findAll(){
List<Brand> brands = brandService.findAll();
return new Result<List<Br

本文档展示了如何在Spring Boot中创建商品微服务的Brand模块,包括使用MyBatis进行增删改查操作,实现条件、分页查询,并通过Postman进行测试。此外,还介绍了全局异常处理类的创建。
最低0.47元/天 解锁文章
1284





