电商项目(六)----后台添加商品中的查询商品分类

一、实现添加商品的接口

1. 在common_item服务中实现商品分类查询

1.1 创建controller
package com.bjsxt.item.controller;

import com.bjsxt.item.service.ItemCategoryService;
import com.bjsxt.pojo.TbItemCat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/service/itemCategory")
public class ItemCategoryController {
    @Autowired
    private ItemCategoryService itemCategoryService;
    /**
     * 根据父节点查询子节点
     */
    @RequestMapping("/selectItemCategoryByParentId")
    public List<TbItemCat> selectItemCategoryByParentId(@RequestParam Long id){
        return itemCategoryService.selectItemCategoryByParentId(id);
    }
}

1.2 创建service
package com.bjsxt.item.service;

import com.bjsxt.pojo.TbItemCat;

import java.util.List;

public interface ItemCategoryService {
    //根据父节点查询子节点  商品类目
    List<TbItemCat> selectItemCategoryByParentId(Long id);
}

1.3 创建serviceImpl
package com.bjsxt.item.service.impl;

import com.bjsxt.item.service.ItemCategoryService;
import com.bjsxt.mapper.TbItemCatMapper;
import com.bjsxt.pojo.TbItemCat;
import com.bjsxt.pojo.TbItemCatExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ItemCategoryServiceImpl implements ItemCategoryService {

    @Autowired
    private TbItemCatMapper tbItemCatMapper;
    /**
     * 根据父节点查询子节点
     * @param id
     * @return
     */
    @Override
    public List<TbItemCat> selectItemCategoryByParentId(Long id) {


        TbItemCatExample example = new TbItemCatExample();
        example.createCriteria().andParentIdEqualTo(id).andStatusEqualTo(1);

        List<TbItemCat> tbItemCats = tbItemCatMapper.selectByExample(example);


        return tbItemCats;
    }
}

测试:父节点为1的所有的子节点数据。

在这里插入图片描述

2. 在backend_item服务中实现商品分类查询

2.1 创建controller
package com.bjsxt.backenditem.controller;

import com.bjsxt.backenditem.service.ItemCategoryService;
import com.bjsxt.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/backend/itemCategory")
public class ItemCategoryController {

    @Autowired
    private ItemCategoryService itemCategoryService;

    /**
     * 查询商品类目:根据类目id,查询当前类目的子节点
     */
    @RequestMapping("/selectItemCategoryByParentId")
    public Result selectItemCategoryByParentId(@RequestParam(value = "id",defaultValue = "0") Long id){
        try{
            Result result = itemCategoryService.selectItemCategoryByParentId(id);
            return result;

        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.build(500,"error");
    }
}

2.2 创建service
package com.bjsxt.backenditem.service;

import com.bjsxt.utils.Result;

public interface ItemCategoryService {
    Result selectItemCategoryByParentId(Long id);
}

2.3 创建serviceImpl
package com.bjsxt.backenditem.service.impl;

import com.bjsxt.backenditem.feign.CommonItemFeignClient;
import com.bjsxt.backenditem.service.ItemCategoryService;
import com.bjsxt.pojo.TbItemCat;
import com.bjsxt.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemCategoryServiceImpl implements ItemCategoryService {

    @Autowired
    private CommonItemFeignClient commonItemFeignClient;
    @Override
    public Result selectItemCategoryByParentId(Long id) {
        List<TbItemCat> tbItemCats = commonItemFeignClient.selectTbItemAllByPage(id);
        System.out.println(tbItemCats);
        if(tbItemCats.size()>0 && tbItemCats!=null){
            return  Result.ok(tbItemCats);

        }
        return Result.error("查无结果");
    }
}

2.4 创建FeignClient

在这里插入图片描述

2.5 测试

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
熟悉项目开发过程SSM框架、JSP、Mysql使用,知道各技术之间的如何衔接; 考虑到部分学生只需要学习前台(买家)或是后台后台),故将电商系统分为电商系统前台和电商系统后台两个项目, 当前课程包含电商系统前台和电商系统后台 该课程主要涉及到的技术有:  项目涉及的技术:  1、前端:jsp、css、javascript、jQuery(js框架)、bootstrap框架 2、后台:Spring MVC、Spring、Mybatis框架、javaMail进行邮件发送、jstl 、jstl自定义分页标签、代码生成器等 3、数据库:Mysql 4、服务器:Tomcat项目开发涉及的功能: 1、项目以及数据库搭建 2、用户登录、退出3、用户注册、邮件发送、以及用户信息激活4、首页商品信息页面搭建以及查询功能实现5、查询商品明细6、加入商品至购物车、删除、更新、清除购物车商品信息7、确认订单信息8、订单页面搭建以及下订单功能实现9、查询我的购物车以及订单信息10、商品明细查看,商品修改,商品下架11、商品类型管理12、订单管理13、代码机器人使用等等其他实战项目:java项目实战之电商系统全套(前台和后台)(java毕业设计ssm框架项目)https://edu.csdn.net/course/detail/25771 java项目之oa办公管理系统(java毕业设计)https://edu.csdn.net/course/detail/23008 java项目之hrm人事管理项目(java毕业设计)https://edu.csdn.net/course/detail/23007 JavaWeb项目实战之点餐系统前台https://edu.csdn.net/course/detail/20543 JavaWeb项目实战之点餐系统后台https://edu.csdn.net/course/detail/19572 JavaWeb项目实战之宿舍管理系统(Java毕业设计含源码)https://edu.csdn.net/course/detail/26721 JavaWeb项目实战之点餐系统全套(前台和后台)https://edu.csdn.net/course/detail/20610 java项目实战之电子商城后台(java毕业设计SSM框架项目)https://edu.csdn.net/course/detail/25770 java美妆商城项目|在线购书系统(java毕业设计项目ssm版)https://edu.csdn.net/course/detail/23989 系统学习课程:JavaSE基础全套视频(环境搭建 面向对象 正则表达式 IO流 多线程 网络编程 java10https://edu.csdn.net/course/detail/26941 Java Web从入门到电商项目实战挑战万元高薪(javaweb教程)https://edu.csdn.net/course/detail/25976其他素材版(毕业设计或课程设计)项目:点击老师头像进行相关课程学习
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值