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


相关推荐

  • webservice实例java_Java WebService(实战) 简单实例

    webservice实例java_Java WebService(实战) 简单实例一、准备工作(以下为本实例使用工具)1、MyEclipse10.7.12、JDK1.6.0_22二、创建服务端1、创建【WebServiceProject】,命名为【TheService】。2、创建【Class】类,命名为【ServiceHello】,位于【com.hyan.service】包下。3、编写供客户端调用的方法,即编译方法代码。4、进行编译说明:编译失败的话,请将该项目引用的jd…

    2022年7月21日
    12
  • 背包问题九讲(转)

    背包问题九讲(转)

    2021年8月7日
    48
  • git config配置

    git config配置

    2022年2月20日
    49
  • IOSG Ventures宣布加入Celer状态守卫者网络以及cBridge流动性桥接网络

    IOSG Ventures宣布加入Celer状态守卫者网络以及cBridge流动性桥接网络IOSGVentures宣布加入Celer状态守卫者网络,并已建立Celer验证人节点。同时,IOSGVentures也宣布加入CelercBridge流动性桥接网络,为其提供流动性。IOSGVentures将与Celer共同维护其二层扩容网络的可用性和安全性,并为其生态发展提供持续可靠的基础设施服务。IOSGVentures现已成为Celer状态守卫者网络验证人节点IOSGVentures成立于2017年,是由社区驱动的研究型早期美元基金,在中国、美国和新…

    2022年6月4日
    31
  • linux top cpu核数查看,Linux怎么查看CPU核数?

    linux top cpu核数查看,Linux怎么查看CPU核数?在Linux中,可以使用“cat/proc/cpuinfo|grep”cpucores”|uniq”来查看CPU核数,即每个物理CPU中core的个数。课程推荐:《linux课程》一、知识点介绍1、cpu信息记录在/proc/cpuinfo中。2、Linux中的Top相当于win系统下的任务管理器,也可以用来查询3、CPU总核数=物理CPU个数*每颗物理CPU的核数4、总逻辑CP…

    2022年10月30日
    0
  • adfs是什么_培训与开发的概念

    adfs是什么_培训与开发的概念(如您转载本文,必须标明本文作者及出处。如有任何疑问请与我联系me@nap7.com)ADFS相关开发技术的中文资料相对匮乏,之前在弄这个东西的时候搞的比较辛苦,因此总结此文档,以解后人之忧。本文会首先介绍与联合身份验证有关的概念及相关的系统设计意图,随后会对ADFS联合身份验证的配置过程、结构及处理流程进行阐述。然后会基于已有的系统提出一个支持多ADFS联合身份验证的改进实例…

    2022年10月27日
    0

发表回复

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

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