============= 后端_分类列表 ============= 首页------>编辑页------>发布页 写文章 发布 发布页: ____________________________ | 摘要/分类/标签 X| |----------------------------| | ________________________ | | | | | | | | | | | | | | | 文章摘要 | | | | | | | | | | | |________________________| | | _______________ | | 文章分类 | V|---> 分类列表 | |_______________| | | ___ ___ ___ | | 文章标签 |x | |x | |x |---> 标签列表 | |___| |___| |___| | | ______ ______ | | | 取消 | | 发布 |---> 发布文章 | |______| |______| | |____________________________| 1 分类服务 1.1 分类服务接口 /ysdblog-api/src/main/java/com/weihome/ysdblog/service/CategoryService.java: public interface CategoryService { ... /** * 查询分类列表 */ public Result list(); ... } 1.2 分类服务实现 /ysdblog-api/src/main/java/com/weihome/ysdblog/service/impl/CategoryServiceImpl.java: ... public class CategoryServiceImpl implements CategoryService { ... @Override public Result list() { List categories = categoryMapper.selectList( new LambdaQueryWrapper()); return Result.success(copyList(categories)); } private List copyList(List categories) { List categoryVos = new ArrayList<>(); for (Category category: categories) categoryVos.add(copy(category)); return categoryVos; } private CategoryVo copy(Category category) { CategoryVo categoryVo = new CategoryVo(); BeanUtils.copyProperties(category, categoryVo); return categoryVo; } ... } 2 分类控制器 /ysdblog-api/src/main/java/com/weihome/ysdblog/controller/CategoryController.java: @RestController @RequestMapping("category") public class CategoryController { @Autowired private CategoryService categoryService; /** * 查询分类列表 */ @GetMapping("list") public Result list() { return categoryService.list(); } } 3 运行测试 Postman GET localhost:8888/category/list ------------------------------------ { "success": true, "code": 200, "msg": "success", "data": [ { "id": 1, "avatar": "category_a.png", "categoryName": "category_a" }, { "id": 2, "avatar": "category_b.png", "categoryName": "category_b" }, { "id": 3, "avatar": "category_c.png", "categoryName": "category_c" }, { "id": 4, "avatar": "category_d.png", "categoryName": "category_d" }, { "id": 5, "avatar": "category_e.png", "categoryName": "category_e" } ] }