|
|
|
@ -0,0 +1,54 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* https://www.mall4j.com/
|
|
|
|
|
*
|
|
|
|
|
* 未经允许,不可做商业用途!
|
|
|
|
|
*
|
|
|
|
|
* 版权所有,侵权必究!
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.yami.shop.api.controller; // 定义类所在的包
|
|
|
|
|
|
|
|
|
|
import java.util.List; // 引入Java的List接口
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 引入Spring的@Autowired注解
|
|
|
|
|
import com.yami.shop.common.response.ServerResponseEntity; // 引入服务器响应实体类
|
|
|
|
|
import org.springframework.web.bind.annotation.*; // 引入Spring Web的注解
|
|
|
|
|
|
|
|
|
|
import com.yami.shop.bean.app.dto.CategoryDto; // 引入分类DTO类
|
|
|
|
|
import com.yami.shop.bean.model.Category; // 引入分类模型类
|
|
|
|
|
import com.yami.shop.service.CategoryService; // 引入分类服务类
|
|
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag; // 引入Swagger的Tag注解
|
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter; // 引入Swagger的Parameter注解
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation; // 引入Swagger的Operation注解
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; // 引入Hutool工具类库中的BeanUtil工具类
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CategoryController类,用于管理商品分类。
|
|
|
|
|
* 该类包含获取分类信息列表的方法。
|
|
|
|
|
* @作者 lanhai
|
|
|
|
|
*/
|
|
|
|
|
@RestController // 标注这是一个控制器类,并且其返回结果直接写入HTTP响应体中,而不是视图名称
|
|
|
|
|
@RequestMapping("/category") // 定义请求路径的根地址为/category
|
|
|
|
|
@Tag(name = "分类接口") // 给API文档添加标签,描述这个控制器的功能
|
|
|
|
|
public class CategoryController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CategoryService categoryService; // 自动注入分类服务类
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分类信息列表接口
|
|
|
|
|
* @param parentId 分类ID,默认值为0
|
|
|
|
|
* @return 服务器响应实体,包含分类信息列表
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/categoryInfo")
|
|
|
|
|
@Operation(summary = "分类信息列表", description = "获取所有的产品分类信息,顶级分类的parentId为0,默认为顶级分类")
|
|
|
|
|
@Parameter(name = "parentId", description = "分类ID", required = false)
|
|
|
|
|
public ServerResponseEntity<List<CategoryDto>> categoryInfo(@RequestParam(value = "parentId", defaultValue = "0") Long parentId) {
|
|
|
|
|
List<Category> categories = categoryService.listByParentId(parentId);
|
|
|
|
|
List<CategoryDto> categoryDtos = BeanUtil.copyToList(categories, CategoryDto.class);
|
|
|
|
|
return ServerResponseEntity.success(categoryDtos);
|
|
|
|
|
}
|
|
|
|
|
}
|