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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Hadoop框架:NameNode工作机制详解

    Hadoop框架:NameNode工作机制详解

    2020年11月20日
    154
  • pyinstall 使用「建议收藏」

    pyinstall 使用「建议收藏」https://blog.csdn.net/HW140701/article/details/93494869

    2025年8月11日
    2
  • 自监督学习(self-supervised learning)(20201124)

    自监督学习(self-supervised learning)(20201124)看论文总是会看出来一堆堆奇奇怪怪的名词。从远程监督、有监督、半监督、无监督开始,最近又看到了一个自监督。首先先对上面的概念进行简述:半监督(semi-supervisedlearning):利用好大量无标注数据和少量有标注数据进行监督学习;远程监督(distant-supervisedlearning):利用知识库对未标注数据进行标注;无监督:不依赖任何标签值,通过对数据内在特征的挖掘,找到样本间的关系,比如聚类相关的任务。自监督:利用辅助任务从无监督的数据中挖掘大量自身的信息。

    2022年9月14日
    3
  • js获取当前时间标准格式_js获取当前时间年月日并输出

    js获取当前时间标准格式_js获取当前时间年月日并输出/** *获取当前时间格式:yyyy-MM-ddHH:MM:SS */functiongetCurrentTime(){   vardate=newDate();//当前时间   varmonth=zeroFill(date.getMonth()+1);//月   varday=zeroFill(date.getDate());//日   …

    2022年9月23日
    4
  • 计算机信息计量单位中的1k代表多少字节,1k等于多少字节

    计算机信息计量单位中的1k代表多少字节,1k等于多少字节一、1K字节等于多少字节1KB=1024B,其中1024=2的10次方。字节(Byte/bait/n.)是计算机信息技术用于计量存储容量的一种计量单位,通常情况下一字节等于八位,也表示一些计算机编程语言中的数据类型和语言字符。国际单位制(SI)1KB=1024B;1MB=1024KB=1024*1024B。1B(byte,字节)=8bit;1KB(Kilobyte,千字节)=1000B…

    2022年5月26日
    219
  • ansi是什么编码格式_ansi编码是什么意思

    ansi是什么编码格式_ansi编码是什么意思用Notepad++创建一个文本文件text.txt,其默认编码格式为ANSI(乍看之下,还以为是ASCII呢),输入汉字居然不是乱码:保存为test.txt,发送给你美国的同事Bob。他也用Notepad++,不幸的是,却发现你的文件内容是这样的:也许你会认为:你用的是中文系统,能正常显示中文;他用的是英文系统,不能显示中文!这么想,好像很有道理呢!但是再细想一下:一个系

    2022年9月24日
    2

发表回复

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

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