提交 31ea6bb9 authored 作者: 吴德鹏's avatar 吴德鹏

pc一级分类

上级 f75887bc
package com.example.afrishop_v3.vo;
import com.example.afrishop_v3.models.TbCfDescripiton;
import lombok.Data;
import java.util.List;
/**
* @Auther: wudepeng
* @Date: 2020/11/23
* @Description:商品分类
*/
@Data
public class Category {
private String id;
private String category;
private List<TbCfDescripiton> categoryList;
}
package com.example.afrishop_v3.website.controller;
import com.example.afrishop_v3.base.Result;
import com.example.afrishop_v3.models.TbCfDescripiton;
import com.example.afrishop_v3.models.TbCfGoodstwotype;
import com.example.afrishop_v3.repository.TbCfDescripitonRepository;
import com.example.afrishop_v3.repository.TbCfGoodstwotypeRepository;
import com.example.afrishop_v3.repository.TbCfGoodstypeRepository;
import com.example.afrishop_v3.vo.Category;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
/**
* @Auther: wudepeng
* @Date: 2020/11/23
* @Description:PC官网首页商品分类管理
*/
@RestController
@RequestMapping(value = "/website/column")
public class ColumnController {
private final TbCfGoodstypeRepository repository;
private final TbCfGoodstwotypeRepository secondaryRepository;
private final TbCfDescripitonRepository tertiaryRepository;
public ColumnController(TbCfGoodstypeRepository repository, TbCfGoodstwotypeRepository secondaryRepository, TbCfDescripitonRepository tertiaryRepository) {
this.repository = repository;
this.secondaryRepository = secondaryRepository;
this.tertiaryRepository = tertiaryRepository;
}
/**
* 查询所有一级分类
*/
@GetMapping
public Result findTopCategory() {
return new Result(repository.findAll());
}
/**
* 查询一级分类的子分类
*/
@GetMapping("/{id}")
public Result findCategoryChildrens(@PathVariable("id") String id) {
LinkedList<Category> categoryList = new LinkedList();
//二级分类
List<TbCfGoodstwotype> secondaryCategory = secondaryRepository.findAllByGoodstypeId(id);
secondaryCategory.forEach(category -> {
//三级分类
List<TbCfDescripiton> tertiaryCategory = tertiaryRepository.findAllByGoodstwotypeId(category.getGoodstwotypeId());
Category c = new Category();
c.setId(category.getGoodstwotypeId());
c.setCategory(category.getGoodstwotypeTitle());
c.setCategoryList(tertiaryCategory);
categoryList.add(c);
});
return new Result(categoryList);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论