10.10.10.1可以设置为网关吗_个人如何做跨境电商

10.10.10.1可以设置为网关吗_个人如何做跨境电商【大型电商项目开发】商品服务-配置网关路由与路径重写-10

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

一:导入pms_category数据库

在这里插入图片描述

二:获取三级列表数据

1.在CategoryController修改list方法

/** * 查出所有分类以及子分类,以树状结构组装起来 * @return */
    @RequestMapping("/list/tree")
    public R list(){ 
   
         List<CategoryEntity> entities = categoryService.listWithTree();
        return R.ok().put("data", entities);
    }

2.在CategoryEntity添加子分类信息

/** * 当前菜单的所有子分类 * @TableField(exist = false) * 数据表不存在此字段 */
	@TableField(exist = false)
	private List<CategoryEntity> children;

3.在CategoryServiceImpl重写listWithTree方法

/** * 查询所有清单 * @return */
    List<CategoryEntity> listWithTree();
@Override
    public List<CategoryEntity> listWithTree() { 
   
        //1.查出所有分类
        List<CategoryEntity> entities = categoryDao.selectList(null);
        //2.组装成父子的结构
        //2.1找到所有的一级分类
        List<CategoryEntity> level1Menus = entities.stream().filter((categoryEntity) -> { 
   
            return categoryEntity.getParentCid() == 0;
        }).map((menu)->{ 
   
            menu.setChildren(getChildrens(menu,entities));
            return menu;
        }).sorted((menu1,menu2)->{ 
   
            return (menu1.getSort() == null ? 0 : menu1.getSort()) -(menu2.getSort() == null?0:menu2.getSort());
        }).collect(Collectors.toList());
        return level1Menus;
    }

    /** * 递归拆询所有菜单的子菜单 * @return */
    private List<CategoryEntity> getChildrens(CategoryEntity root , List<CategoryEntity> all){ 
   
        List<CategoryEntity> children = all.stream().filter((categoryEntity) -> { 
   
            return categoryEntity.getParentCid().equals(root.getCatId());
        }).map((categoryEntity)->{ 
   
            //找到子菜单
            categoryEntity.setChildren(getChildrens(categoryEntity,all));
            return categoryEntity;
        }).sorted((menu1,menu2)->{ 
   
            //菜单排序
            return (menu1.getSort() == null ? 0 : menu1.getSort()) -(menu2.getSort() == null?0:menu2.getSort());
        }).collect(Collectors.toList());
        return children;
    }

3.启动gulimail-product项目

http://127.0.0.1:10000/product/category/list/tree

在这里插入图片描述

三:前端模块开发

1.启动renren-fast模块

在这里插入图片描述

2.启动renren-fast-vue模块

打开vscode,使用npm run dev 开启项目
在这里插入图片描述

3.搭建菜单

1.在系统管理模块添加商品系统目录
在这里插入图片描述
2.在商品系统模块添加分类维护菜单
在这里插入图片描述
注:product/category路径的/会被替换为product-category
3.在src/views/modules下新建product商品文件夹,然后创建category.vue文件在这里插入图片描述
4.创建树形模板
打开https://element.eleme.cn/#/zh-CN/component/tree的Tree树形控件,复制相关代码

<template>
  <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" ></el-tree>
</template>

<script> export default { 
      /** * 数据集合 */ data() { 
      return { 
      data: [], defaultProps: { 
      children: "children", label: "label", }, }; }, /** * 生命周期 */ created(){ 
      /** * 创建组件时,会调用此方法 */ this.getMenus(); }, /** * 方法集合 */ methods: { 
      handleNodeClick(data) { 
      console.log(data); }, /** * 获取三级三单 */ getMenus() { 
      this.$http({ 
      url: this.$http.adornUrl("/product/category/list/tree"), method: "get", }).then(data=>{ 
      console.log("成功获取到菜单数据。。。"+ data); }); }, }, }; </script>

<style> </style>

注:此时访问/product/category/list/tree会接口404异常,涉及到跨域等问题
5.打开static/config/index.js修改发送请求得地址,统一发送给gateway网关,由网关发送给需要调用的接口

/**
 * 开发环境
 */
;(function () {
  window.SITE_CONFIG = {};

  // api接口请求地址
  window.SITE_CONFIG['baseUrl'] = 'http://localhost:88/api';

  // cdn地址 = 域名 + 版本号
  window.SITE_CONFIG['domain']  = './'; // 域名
  window.SITE_CONFIG['version'] = '';   // 版本号(年月日时分)
  window.SITE_CONFIG['cdnUrl']  = window.SITE_CONFIG.domain + window.SITE_CONFIG.version;
})();

6.重启项目后发现图片验证码无法加载,此时我们需要对renren-fast项目的pom文件进行配置

4.修复图片验证码无法加载问题

默认将网关的请求转向renren-fast项目
1.在renren-fast项目中配置相关依赖

<!--引入common依赖--> <dependency> <groupId>com.sysg.gulimail</groupId> <artifactId>gulimail-common</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>

2.将renren-fast项目添加到nacos配置中心当中
1)在application添加name和nacos地址

spring:
  application:
    name: renren-fast
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848

2)在主启动类添加注解@EnableDiscoveryClient

package io.renren;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/** * @EnableDiscoveryClient * 用于服务的注册和发现 */
@EnableDiscoveryClient
@SpringBootApplication
public class RenrenApplication { 
   

	public static void main(String[] args) { 
   
		SpringApplication.run(RenrenApplication.class, args);
	}

}

3)重启renren-fast项目,在nacos的服务列表查看renren-fast
在这里插入图片描述
4)在gateway的application.yml文件中添加配置

spring:
  cloud:
    gateway:
      #路由规则
      routes:
        ## 前端项目,/api
        - id: admin_route
          uri: lb://renren-fast
          predicates:
            - Path=/api/**
          filters:
           #路径重写
            - RewritePath=/api/(?<segment>.*),/renren-fast/$\{segment}

## http://localhost:88/captcha.jpg  http://localhost:8080/renrne-fast/captcha.jpg

在这里插入图片描述
注:此时发生了跨域问题,所以无法访问

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/164736.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • LoadRunner教程(1)-LoadRunner简介与安装

    LoadRunner教程(1)-LoadRunner简介与安装LoadRunner,是一种预测系统行为和性能的负载测试工具。通过以模拟上千万用户实施并发负载及实时性能监测的方式来确认和查找问题,LoadRunner能够对整个企业架构进行测试。企业使用LoadRunner能最大限度地缩短测试时间,优化性能和加速应用系统的发布周期。LoadRunner可适用于各种体系架构的自动负载测试,能预测系统行为并评估系统性能。下载及其安装过程参照如下,记住安装成英文…

    2022年5月23日
    37
  • 仿酷狗音乐播放器已开源!

    仿酷狗音乐播放器已开源!这是Redrain仿酷狗音乐播放器的完整代码,目的是帮助更多使用DuiLib的朋友学习这个库,如果代码有bug,或者对程序有疑问,可以联系我个人QQ或者QQ群,我经常在DuiLibQQ群活动,这个代码中包含了webkit内核浏览器、音乐播放类、菜单类、换肤功能等等。

    2022年6月26日
    54
  • PAT乙级题目答案汇总 PAT (Basic Level) Practice (中文)[通俗易懂]

    PAT乙级题目答案汇总 PAT (Basic Level) Practice (中文)[通俗易懂]题目列表:标号题目链接分数博客链接完成时间1001害死人不偿命的(3n+1)猜想151001害死人不偿命的(3n+1)猜想(15分)2020/8/01

    2022年5月29日
    36
  • springboot启动流程概述_简述app启动的主要流程

    springboot启动流程概述_简述app启动的主要流程又回顾了springboot启动流量,有了新的理解,进行以下补充:1、listeners.starting()等方法,第一次出现了误解,以为是启动监听器,但是我很奇怪监听器为什么要启动。再次看源码,才知道不同的方法是用来发布不同的事件,此方法就是发布ApplicationStartingEvent事件。可见看源码还是要耐心。…

    2022年8月21日
    6
  • Java8高中并发

    Java8高中并发

    2022年1月8日
    39
  • 小米5 Android 8.0解bl,小米解BL锁超详细的图文教程「建议收藏」

    小米5 Android 8.0解bl,小米解BL锁超详细的图文教程「建议收藏」BL锁全称bootloader锁,其中bootloader中文名称为“启动加载”,其主要作用是为了保护用户的隐私数据安全,在日常使用的时候感受不到BL锁的存在,但是如果你要对手机进行刷机的话,第一步就是必须先解除手机里的BL锁,部分机子不需要解BL锁,手机是否需要解锁请到手机官方网站进行查看或者咨询。解BL锁会清除手机所有的数据,相当于手机恢复出厂设置,记得提前备份好手机里的所有资料以下是小米解锁…

    2022年5月20日
    63

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号