将 pms_catelog.sql的语句在pms.catagory中执行。
    一级菜单-》二级菜单-》三级菜单

    在服务中查询商品分类,以树形结构返回。
    找到catagorycontroler
    修改/list 为 /list/tree
    新增方法
    catagoryService.listWithTree();
    会在接口中新增方法,实现类中需要覆盖该方法,

    1. @Override
    2. public List<CategoryEntity> listWithTree() {
    3. // 1.查询商品分类信息
    4. List<CategoryEntity> entities = baseMapper.selectList(null);
    5. // 2.以树形结构返回
    6. List<CategoryEntity> level1Entites = entities.stream().filter((entitie) -> {
    7. return entitie.getParentCid() == 0;
    8. }).map((menu)->{
    9. menu.setChildren(getChilderns(menu, entities));
    10. return menu;
    11. }).sorted((menu1, menu2)->{
    12. return (menu1.getSort() == null ? 0 : menu1.getSort())- (menu2.getSort() == null ? 0 : menu2.getSort());
    13. }).collect(Collectors.toList());
    14. return level1Entites;
    15. }

    商品类entity中添加子类属性:

    1. @TableField(exist=false)
    2. private List<CategoryEntity> children;
    1. // 递归查找子菜单
    2. private List<CategoryEntity> getChilderns(CategoryEntity root, List<CategoryEntity> all) {
    3. List<CategoryEntity> children = all.stream().filter((entity) -> {
    4. return entity.getParentCid() == root.getCatId();
    5. }).map((menu)->{
    6. menu.setChildren(getChilderns(menu, all));
    7. return menu;
    8. }).sorted((menu1, menu2)->{
    9. return (menu1.getSort() == null ? 0 : menu1.getSort())- (menu2.getSort() == null ? 0 : menu2.getSort());
    10. }).collect(Collectors.toList());
    11. return children;
    12. }

    利用人人fast后台管理系统,新增商品系统-》分类维护, 目录-》菜单。
    为分类维护菜单添加 路由:product/category

    renren-fast-vue中src/views/modules 新建一个product文件夹,创建category.vue文件
    创建vue组件,套用elementui树形控件。模仿调用后端api模板,请求/product/category/list/tree
    的url

    由于renrenfast-vue调用的是renrenfast,而不是谷粒product服务,因此将renrenfast注册到gateway中,通过88端口网关来访问url才能生效。

    配置网关路由:
    spring:
    cloud:
    gateway:
    routes:

    - id: admin-route
    uri: lb://renren-fast
    predicates:
    - Path=/api/
    filters:
    *- RewritePath=/api/(?.),/renren-fast/${segment}
    同时修改renren-fast-vue中baseurl:’http://localhost:88/api‘;

    再次访问前端项目,可以获取验证码,但无法登录
    Access to XMLHttpRequest at ‘http://localhost:88/api/sys/login‘ from origin ‘http://localhost:8001‘ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
    原因:跨域请求不被允许

    解决跨域:
    1.nginx部署为同一域
    2.服务器配置响应头
    gateway同一配置 ,config/

    1. @Configuration
    2. public class GulimallCorsConfiguration {
    3. @Bean
    4. public CorsWebFilter corsWebFilter(){
    5. UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource();
    6. CorsConfiguration config = new CorsConfiguration();
    7. // 1.配置跨域
    8. config.addAllowedHeader("*");
    9. config.addAllowedMethod("*");
    10. config.addAllowedOrigin("*");
    11. config.setAllowCredentials(true);
    12. corsConfigurationSource.registerCorsConfiguration("/**", config);
    13. return new CorsWebFilter(corsConfigurationSource);
    14. }
    15. }

    renren-fast中也配置了跨域,需要注释

    gateway需要修改商品服务路由,同时需要将商品服务配置到配置中心。

    三级商品菜单删除功能:

    mybait plus 逻辑删除

    前端删除部分…

    品牌管理: