乐优商城(一)介绍和项目搭建

news2024/9/23 5:27:56

1. 乐优商城介绍

1.1 项目介绍

  • 乐优商城是一个全品类的电商购物网站(B2C)
  • 用户可以在线购买商品、加入购物车、下单
  • 可以评论已购买商品
  • 管理员可以在后台管理商品的上下架、促销活动
  • 管理员可以监控商品销售状况
  • 客服可以在后台处理退款操作
  • 希望未来 3 到 5 年可以支持千万用户的使用

1.2 项目架构

1.3 系统架构解读

整个乐优商城可以分为两部分:后台管理系统、前台门户系统。

  • 后台管理系统:

后台系统主要包含以下功能:
商品管理,包括商品分类、品牌、商品规格等信息的管理
销售管理,包括订单统计、订单退款处理、促销活动生成等
用户管理,包括用户控制、冻结、解锁等
权限管理,整个网站的权限控制,采用JWT鉴权方案,对用户及API进行权限控制
统计,各种数据的统计分析展示
后台系统会采用前后端分离开发,而且整个后台管理系统会使用 Vue.js 框架搭建出单页应用(SPA)。

  • 前台门户系统:

前台门户面向的是客户,包含与客户交互的一切功能:
搜索商品
加入购物车
下单
评价商品等等
前台系统我们会使用 Thymeleaf 模板引擎技术来完成页面开发。出于 SEO 优化的考虑,我们将不采用单页应用

无论是前台还是后台系统,都共享相同的微服务集群,包括:

  • 商品微服务:商品及商品分类、品牌、库存等的服务
  • 搜索微服务:实现搜索功能
  • 订单微服务:实现订单相关
  • 购物车微服务:实现购物车相关功能
  • 用户中心:用户的登录注册等功能
  • Eureka注册中心
  • Zuul网关服务

2. 项目搭建

2.1 技术选型

前端技术:

  • 基础的 HTML、CSS、JavaScript(基于 ES6 标准)
  • JQuery
  • Vue.js 2.0 以及基于 Vue 的框架:Vuetify(UI框架)
  • 前端构建工具:WebPack
  • 前端安装包工具:NPM
  • Vue 脚手架:Vue-cli
  • Vue 路由:vue-router
  • Ajax 框架:axios
  • 基于 Vue 的富文本框架:quill-editor
     

后端技术:

  • 基础的 SpringMVC、Spring 5.x 和 MyBatis3
  • Spring Boot 2.2.4 版本
  • Spring Cloud Hoxton.SR1
  • Redis-4.0
  • RabbitMQ-3.4
  • Elasticsearch-6.3
  • nginx-1.14.2
  • FastDFS - 5.0.8
  • MyCat
  • Thymeleaf
  • mysql 5.6

2.2 开发环境

  • IDE:我们使用 Idea 2018.1 版本
  • JDK:统一使用 JDK1.8
  • 项目构建:maven3.3.9 以上版本即可
  • 版本控制工具:git

2.3 域名

我们在开发的过程中,为了保证以后的生产、测试环境统一,尽量都采用域名来访问项目。

一级域名:leyou.com

二级域名:www.leyou.com , api.leyou.com

我们可以通过 switchhost 工具来修改自己的 host 对应的地址,只要把这些域名指向 127.0.0.1,那么跟你用 localhost 的效果是完全一样的。

2.4 创建父工程

创建统一的父工程:leyou,用来管理依赖及其版本。

Create New Project --> Maven --> Next

填写项目信息 --> Next

填写保存的位置 --> Finish

添加依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.leyou.parent</groupId>
    <artifactId>leyou</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <name>leyou</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR1</spring-cloud.version>
        <mybatis.starter.version>1.3.2</mybatis.starter.version>
        <mapper.starter.version>2.0.2</mapper.starter.version>
        <druid.starter.version>1.1.9</druid.starter.version>
        <mysql.version>5.1.32</mysql.version>
        <pageHelper.starter.version>1.2.3</pageHelper.starter.version>
        <leyou.latest.version>1.0.0-SNAPSHOT</leyou.latest.version>
        <fastDFS.client.version>1.26.1-RELEASE</fastDFS.client.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- springCloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- mybatis启动器 -->
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>${mybatis.starter.version}</version>
            </dependency>
            <!-- 通用Mapper启动器 -->
            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper-spring-boot-starter</artifactId>
                <version>${mapper.starter.version}</version>
            </dependency>
            <!-- 分页助手启动器 -->
            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper-spring-boot-starter</artifactId>
                <version>${pageHelper.starter.version}</version>
            </dependency>
            <!-- mysql驱动 -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
            </dependency>
            <!--FastDFS客户端-->
            <dependency>
                <groupId>com.github.tobato</groupId>
                <artifactId>fastdfs-client</artifactId>
                <version>${fastDFS.client.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    
</project>

可以发现,我们在父工程中引入了 SpringCloud 等,很多以后需要用到的依赖,以后创建的子工程就不需要自己引入了。

删除 src 目录,工程结构如下

2.5 创建 Eureka Server

  1. 右键 leyou 项目 --> New Module --> Maven --> Next

填写项目信息 --> Next

填写保存的位置 --> Finish

添加依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>leyou</artifactId>
        <groupId>com.leyou.parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.leyou.registry</groupId>
    <artifactId>leyou-registry</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>


</project>

编写启动类

@SpringBootApplication
@EnableEurekaServer
public class LeyouRegistryApplication {
    public static void main(String[] args) {
        SpringApplication.run(LeyouRegistryApplication.class,args);
    }
}

编写配置文件 application.yaml

server:
  port: 10086
spring:
  application:
    name: leyou-registry
eureka:
  client:
    service-url:
      defaultZone: http://localhost:${server.port}/eureka
    fetch-registry: false
    register-with-eureka: false
  server:
    enable-self-preservation: false
    eviction-interval-timer-in-ms: 5000

工程结构如下

2.6 创建 Zuul

  1. 右键 leyou 项目 --> New Module --> Maven --> Next

填写项目信息 --> Next

填写保存的位置 --> Finish

添加依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>leyou</artifactId>
        <groupId>com.leyou.parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.leyou.gateway</groupId>
    <artifactId>leyou-gateway</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>


</project>

编写启动类

@SpringBootApplication
@EnableZuulProxy
public class LeyouGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(LeyouGatewayApplication.class, args);
    }
}

编写配置

server:
  port: 10010
spring:
  application:
    name: leyou-gateway
eureka:
  client:
    service-url:
      defaultZone: http://localhost:10086/eureka
    registry-fetch-interval-seconds: 5
zuul:
  prefix: /api

2.7 创建商品微服务

2.7.1 商品微服务的结构

因为与商品的品类相关,我们的工程命名为 leyou-item.

需要注意的是,我们的 leyou-item 是一个微服务,那么将来肯定会有其它系统需要来调用服务中提供的接口,获取的接口数据,也需要对应的实体类来封装,因此肯定也会使用到接口中关联的实体类。

因此这里我们需要使用聚合工程,将要提供的接口及相关实体类放到独立子工程中,以后别人引用的时候,只需要知道坐标即可。

我们会在 leyou-item 中创建两个子工程:

  • leyou-item-interface:主要是对外暴露的接口及相关实体类
  • leyou-item-service:所有业务逻辑及内部使用接口

调用关系如图所示:

2.7.2 创建 leyou-item
  1. 右键 leyou 项目 --> New Module --> Maven --> Next

填写项目信息 --> Next

填写保存的位置 --> Finish

删除 src 目录

2.7.3 创建 leyou-item-interface
  1. 右键 leyou-item 项目 --> New Module --> Maven --> Next

填写项目信息 --> Next

填写保存的位置 --> Finish

2.7.4 创建 leyou-item-service
  1. 右键 leyou-item 项目 --> New Module --> Maven --> Next

填写项目信息 --> Next

填写保存的位置 --> Finish

项目结构如下

添加依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>leyou-item</artifactId>
        <groupId>com.leyou.item</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.leyou.item</groupId>
    <artifactId>leyou-item-service</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- web启动器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- eureka客户端 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <!-- mybatis的启动器 -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
        </dependency>
        <!-- 通用mapper启动器 -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
        </dependency>
        <!-- 分页助手启动器 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
        </dependency>
        <!-- jdbc启动器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <!-- mysql驱动 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!--leyou-item-interface-->
        <dependency>
            <groupId>com.leyou.item</groupId>
            <artifactId>leyou-item-interface</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!-- springboot检测服务启动器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>


</project>

编写启动类

@SpringBootApplication
@EnableDiscoveryClient
public class LeyouItemServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(LeyouItemServiceApplication.class, args);
    }
}

编写配置文件

server:
 port: 8081
spring:
 application:
   name: item-service
 datasource:
   url: jdbc:mysql://localhost:3306/leyou
   username: root
   password: zt3742
eureka:
 client:
   service-url:
     defaultZone: http://localhost:10086/eureka
 instance:
   lease-renewal-interval-in-seconds: 5
   lease-expiration-duration-in-seconds: 10 
mybatis:
 type-aliases-package: com.leyou.item.pojo

2.8 添加商品微服务规则

既然商品微服务已经创建,接下来肯定要添加路由规则到 Zuul 中,我们不使用默认的路由规则。

修改 leyou-gateway 工程的 application.yaml 配置文件:

server:
  port: 10010
spring:
  application:
    name: leyou-gateway
eureka:
  client:
    service-url:
      defaultZone: http://localhost:10086/eureka
    registry-fetch-interval-seconds: 5
zuul:
  prefix: /api
  routes:
    item-service: /item/**

2.9 启动测试

  1. 我们分别启动:leyou-registry,leyou-gateway,leyou-item-service

  2. 打开浏览器,访问下面地址

2.10 测试路由规则

为了测试路由规则是否畅通,我们是不是需要在 item-service 中编写一个 controller 接口呢?

其实不需要,SpringBoot 提供了一个依赖:actuator。只要我们添加了 actuator 的依赖,它就会为我们生成一系列的访问接口:

  • /info
  • /health
  • /refresh

访问 Eureka 控制台:

这就是 actuator 提供的接口,我们点击访问:

因为我们没有添加信息,所以是一个空的 json,但是可以肯定的是:我们能够访问到 item-service 了。

接下来我们通过路由访问试试,根据路由规则,我们需要访问的地址是:

2.11 创建通用工具模块

有些工具或通用的约定内容,我们希望各个服务共享,因此需要创建一个工具模块:leyou-common

  1. 右键 leyou 项目 --> New Module --> Maven --> Next

填写项目信息 --> Next

填写保存的位置 --> Finish

2.12 最终项目结构

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1080002.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【机器学习】集成学习(以随机森林为例)

文章目录 集成学习随机森林随机森林回归填补缺失值实例&#xff1a;随机森林在乳腺癌数据上的调参附录参数 集成学习 集成学习&#xff08;ensemble learning&#xff09;是时下非常流行的机器学习算法&#xff0c;它本身不是一个单独的机器学习算法&#xff0c;而是通过在数据…

Rust入门基础

文章目录 Rust相关介绍为什么要用Rust&#xff1f;Rust的用户和案例 开发环境准备安装Rust更新与卸载Rust开发工具 Hello World程序编写Rust程序编译与运行Rust程序 Cargo工具Cargo创建项目Cargo构建项目Cargo构建并运行项目Cargo检查项目Cargo为发布构建项目 Rust相关介绍 为…

关于串口服务器及转接线的一些基础知识笔记

1.普通个人计算机9针串口为232接口&#xff0c;部分特殊工业计算机为485接口。接线方式差异较大&#xff0c;容易区分。 2.串口服务器的作用&#xff1a;带串口的设备&#xff08;支持常见232、485/422接口方式&#xff09;&#xff0c;将其串口数据信号通过串口服务器转为网络…

角谷猜想:键盘输入一个整数,输出角谷猜想验证过程

键盘输入一个整数&#xff0c;输出角谷猜想验证过程。 (本笔记适合python循环、if条件语句、字符串格式化输出的 coder 翻阅) 【学习的细节是欢悦的历程】 Python 官网&#xff1a;https://www.python.org/ Free&#xff1a;大咖免费“圣经”教程《 python 完全自学教程》&…

cdsn目录处理:空行替换2个```,在2个```中间添加“# 空行文本后遇到的第1行文字”?

原标题&#xff1a; python查找替换&#xff1a;查找空行&#xff0c;空行前后添加&#xff0c;中间添加 # 空格 空行后遇到的第1行文字&#xff1f;初始代码 查找空行空行前后添加 中间添加 # 空行后遇到的第1行文字txt 36 96 159 8 72可以使用Python的字符串处理函数来查找…

【数据库系统概论】第一章数据库绪论

第一章目录&#xff1a; 1.1数据库系统概述 1.1.1四个基本概念 数据&#xff1a; 数据库&#xff1a;Database -DB 数据库管理系统&#xff08;DBMS&#xff09; 数据库系统&#xff08;DBS&#xff09;&#xff08;有四个组成要素&#xff09; 1.1.2数据管理技术的产生…

【电商API封装接口】电商百万商品资源一键导入,助力企业流量变现

电商API接口是淘宝开放平台提供的一组数据接口&#xff0c;供开发者使用来获取淘宝平台上商品、店铺、订单等相关信息。根据功能和分类&#xff0c;淘宝API主要包括以下几个方面&#xff1a; 1. 商品API&#xff1a;提供了搜索、详情、评价等与商品相关的接口&#xff0c;可以…

vue2 打印数据 以及使用 (2)

安装 To install using npm:npm install print-js --saveTo install using yarn:yarn add print-js页面效果 <template><div><table width"100%" height"100%" border"1"><tr><td colspan"1">1</td&…

python图片处理:添加背景文生图(2)

文生图3.0&#xff1a;添加背景图片 3个回车文生图꧂写在前面&#xff1a;肉麻的话꧁ 哈哈&#xff0c;我明白了&#xff01;请允许我再试一次以幽默的方式来重新描述文本&#xff1a; 亲爱的主人大大&#xff0c;你是超级棒的&#xff01;如果你不想处理枯燥的代码&#xff0…

前端TypeScript学习day03-TS高级类型

(创作不易&#xff0c;感谢有你&#xff0c;你的支持&#xff0c;就是我前行的最大动力&#xff0c;如果看完对你有帮助&#xff0c;请留下您的足迹&#xff09; 目录 TypeScript 高级类型 class 类 class继承 extends implements 类成员可见性 public protected …

c语言终点站--文件操作

前言&#xff1a; 为什么要学习文件操作呢&#xff1f;想要知道这个问题&#xff0c;我们就需要先了解什么是数据的可持久化。 那么什么是数据的可持久化呢&#xff1f;数据的可持久化就是把内存中的数据对象永久的保存在电脑的磁盘文件中&#xff0c;将程序数据在持久状态和…

mysql面试题40:列值为null或者空字符串时,查询是否会用到索引?

该文章专注于面试,面试只要回答关键点即可,不需要对框架有非常深入的回答,如果你想应付面试,是足够了,抓住关键点 面试官:列值为null或者空字符串时,查询是否会用到索引? 当列的值为NULL时,查询可能会使用索引,但具体是否使用索引取决于数据库的优化器和查询条件。…

点向行列连边的网络流图优化成行列连边的二分图:CF1592F2

https://www.luogu.com.cn/problem/CF1592F2 做完F1&#xff0c;然后用1的结论来思考。 场上推了几个性质。首先op4的操作行列必然两两不同&#xff0c;所以op4最多 max ⁡ ( n , m ) \max(n,m) max(n,m) 次。然后手玩发现只有除 ( n , m ) (n,m) (n,m) 的三个格子都为1&am…

ChatGPT 是如何产生心智的? | 京东云技术团队

一、前言 - ChatGPT真的产生心智了吗&#xff1f; 来自斯坦福大学的最新研究结论&#xff0c;一经发出就造成了学术圈的轰动&#xff0c;“原本认为是人类独有的心智理论&#xff08;Theory of Mind&#xff0c;ToM&#xff09;&#xff0c;已经出现在ChatGPT背后的AI模型上”…

芯科蓝牙BG27开发笔记10-BG27样板调试

样板使用了1.5V电源&#xff0c;boost升压到1.8V供MCU使用&#xff0c;因此IO通信的电平需要注意&#xff1a; 不能使用常用的5V、3.3V的jlink进行调试&#xff0c;类似的uart通信也一样。 BRD4001A底板的jlink如何使用&#xff1f; 参考开发板套件的说明文档《ug551-brd4194…

purr map walk 学习教程 完整版教程学习

Function reference • purrrhttps://purrr.tidyverse.org/reference/index.htmlMap over multiple input simultaneously (in "parallel") — pmap • purrr 11 Other purrr functions | Functional Programming (stanford.edu) 关注微信&#xff1a;生信小博士 1…

【解决问题思路分析】记录hutool默认使用服务端上次返回cookie的问题解决思路

背景&#xff1a; 本服务需要调用第三方接口获取数据&#xff0c;首先调用public-key接口获取公钥&#xff0c;然后用公钥加密密码&#xff0c;将用户名和密码传入/ticket接口&#xff0c;获取Cookie和response body中的token。 排查思路 由于是调用第三方接口出现问题&…

OnlyOffice文档服务器安装及集成使用

OnlyOffice文档服务器安装及集成使用 一、安装1.使用docker安装2.开启防火墙3.配置4.访问测试 二、应用集成1.前端集成(React)(1).安装onlyoffice/document-editor-react(2).使用 ONLYOFFICE 文档 React 组件 2.后台集成(Java)(1) getFile接口(2) callback接口(3) getFile接口和…

SpringBoot拦截器实现

1.定义一个拦截器类&#xff0c;实现HandlerInterceptor接口 创建一个Interceptor类实现HandlerInterceptor接口&#xff0c;重写preHandle()&#xff0c;postHandle()&#xff0c;afterCompletion() 三个方法 如下代码&#xff0c;我们就创建了一个Spring的拦截器 /*** auth…

战神引擎传奇假设教程

战神引擎传奇假设教程 --------------------------------------------------------------------------------------------------- 传奇这款游戏可以说是一代人的回忆&#xff0c;特别是8090后&#xff0c;传奇对他们有着许许多多的难忘的回忆&#xff0c; 随着时代的发展&…