wangjinhao_branch
wangjinhao 9 months ago
parent c78536267d
commit 756ccbd6b3

@ -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 ID0
* @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);
}
}
Loading…
Cancel
Save