bigtype

/*
SQLyog Ultimate v11.33 (64 bit)
MySQL - 5.7.18-log 
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `t_bigtype` (
	`id` int (11),
	`name` varchar (150),
	`remark` varchar (765),
	`image` varchar (765)
); 
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('1','手机','手机描述','1.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('2','电脑平板','电脑平板描述','2.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('3','智能穿戴','智能穿戴描述','3.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('4','电视','电视描述','4.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('5','大家电','大家电描述','5.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('6','小家电','小家电描述','6.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('7','智能家居','智能家居描述','7.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('8','户外出行','户外出行描述','8.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('9','日用百货','日用百货描述','9.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('10','儿童用品','儿童用品描述','10.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('41','ds','ds','default.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('42','dsds','ds','default.jpg');
insert into `t_bigtype` (`id`, `name`, `remark`, `image`) values('43','22','22','20220226111030000000632.jpg');

smalltype

/*
SQLyog Ultimate v11.33 (64 bit)
MySQL - 5.7.18-log 
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `t_smalltype` (
	`id` int (11),
	`name` varchar (150),
	`remark` varchar (765),
	`bigTypeId` int (11)
); 
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('1','Xiaomi Civi','Xiaomi Civi','1');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('2','Xiaomi 数字系列','Xiaomi 数字系列','1');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('3','Xiaomi MIX系列','Xiaomi MIX系列','1');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('5','小米平板','小米平板','2');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('6','RedmiBook','RedmiBook','2');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('7','小米笔记本','小米笔记本','2');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('10','耳机','耳机','3');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('11','手表','手表','3');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('12','手环','手环','3');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('13','电视','电视','4');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('14','小米电视大师','小米电视大师','4');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('15','电视配件','电视配件','4');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('16','空调','空调','5');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('17','洗衣机','洗衣机','5');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('18','冰箱','冰箱','5');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('19','厨房大电','厨房大电','5');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('20','厨房小电','厨房小电','6');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('21','清洁电器','清洁电器','6');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('22','环境电器','环境电器','6');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('23','生活电器','生活电器','6');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('24','小爱音箱','小爱音箱','7');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('25','路由器','路由器','7');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('26','智能安防','智能安防','7');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('27','智能控制','智能控制','7');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('28','户外出行','户外出行','8');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('29','箱包','箱包','8');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('30','家具日用','家具日用','9');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('31','防护清洁','防护清洁','9');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('32','会员定制','会员定制','9');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('33','个人护理','个人护理','9');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('34','健康','健康','9');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('35','鞋服配饰','鞋服配饰','9');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('36','床品家居','床品家居','9');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('37','礼品周边','礼品周边','9');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('38','儿童用品','儿童用品','10');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('39','Redmi K系列','K系列','1');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('40','Redmi Note系列','Note系列','1');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('41','游戏手机','游戏手机','1');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('44','22','22','3');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('45','是','3 是','2');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('46','ewew','ew','3');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('47','rrr','rrr','2');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('48','43','4343','2');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('49','5','55','4');
insert into `t_smalltype` (`id`, `name`, `remark`, `bigTypeId`) values('50','12','22','7');

package com.java1234.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 商品小类
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2021-11-22 22:03
 */
@TableName("t_smallType")
@Data
public class SmallType implements Serializable {

    private Integer id; // 编号

    private String name; // 名称

    private String remark; // 备注

    private Integer bigTypeId; // 大类id

    @TableField(select = false)
    private BigType bigType;  // 所属商品大类

    @TableField(select = false)
    private List<Product> productList; // 商品集合


}

package com.java1234.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.util.List;

/**
 * 商品大类
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2021-11-22 22:03
 */
@TableName("t_bigType")
@Data
public class BigType {

    private Integer id; // 编号

    private String name; // 名称

    private String remark; // 备注

    private String image="default.jpg"; // 封面图片

    @TableField(select = false)
    private List<SmallType> smallTypeList;//小类集合

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }



}

Mapper

package com.java1234.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.java1234.entity.SmallType;

public interface SmallTypeMapper extends BaseMapper<SmallType> {
}

Service

package com.java1234.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.java1234.entity.SmallType;

public interface ISmallTypeService extends IService<SmallType> {
}

Impl

package com.java1234.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.java1234.entity.SmallType;
import com.java1234.mapper.SmallTypeMapper;
import com.java1234.service.ISmallTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 商品小类Service实现类
 */
@Service("smallTypeService")
public class ISmallTypeServiceImpl extends ServiceImpl<SmallTypeMapper, SmallType> implements ISmallTypeService {

    @Autowired
    private SmallTypeMapper smallTypeMapper;
}

/findCategories

package com.java1234.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.java1234.entity.BigType;
import com.java1234.entity.Product;
import com.java1234.entity.R;
import com.java1234.entity.SmallType;
import com.java1234.service.IBigTypeService;
import com.java1234.service.IProductService;
import com.java1234.service.ISmallTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商品大类Controller
 */
@RestController
@RequestMapping("/bigType")
public class BigTypeController {

    @Autowired
    private IBigTypeService bigTypeService;

    @Autowired
    private ISmallTypeService smallTypeService;

    @Autowired
    private IProductService productService;
    /**
     * 查询所有商品大类
     * @return
     */
    @GetMapping("/findAll")
    public R findAll(){
        List<BigType> bigTypeList = bigTypeService.list();
        Map<String,Object> map=new HashMap<>();
        map.put("message",bigTypeList);
        return R.ok(map);
    }

    /**
     * 获取所有菜单信息
     * @return
     */
    @GetMapping("/findCategories")
    public R findCategories(){
        List<BigType> bigTypeList = bigTypeService.list();
        for(BigType bigType:bigTypeList){
            //获取当前大类的小类id集合
            List<SmallType> smallTypeList=smallTypeService.list(new QueryWrapper<SmallType>().eq("bigTypeId",bigType.getId()));
            bigType.setSmallTypeList(smallTypeList);

            for(SmallType smallType:smallTypeList){
                //获取小类的产品
                List<Product> productList = productService.list(new QueryWrapper<Product>().eq("typeId",smallType.getId()));
                smallType.setProductList(productList);
            }
        }
        Map<String,Object> map=new HashMap<>();
        map.put("message",bigTypeList);
        return R.ok(map);
    }
}


big -> small -> product

01-30 23:22