微服务项目实战 - 电商平台 项目框架及多模块开发

本项目会被分为多个文章去讲解实现

目录

1、项目简介

项目模式

1、B2B模式 B2B (Business to Business)

2、B2C 模式 B2C (Business to Consumer)

3、C2B模式 C2B(CustomertoBusiness)

4、C2C模式 C2C (Customer to Consumer)

5、O2O模式 O2O即Online To Ofline

技术栈

项目架构图

SpringCloud微服务系统架构图​编辑 zmall​编辑

 模块

案例演示

主模块

 zmall-common子模块

zmall-user子模块

1.基于Spring Initialzr方式创建zmall-user用户模块​编辑

2.配置pom.xml。设置父模块,并添加zmall-common公共模块的依赖支持。

 3.添加登录页面及公共资源

4.配置application.yml

 运行结果​


1、项目简介

项目模式

电商模式:市面上有5种常见的电商模式,B2B、B2C、 C2B、 C2C、O2O;

1、B2B模式 B2B (Business to Business)

是指 商家与商家建立的商业关系。如:阿里巴巴

2、B2C 模式 B2C (Business to Consumer)

就是我们经常看到的供应商直接把商品卖给用户,即“商对客” 模式,也就是通常说的商业零售,直接面向消费者销售产品和服务。如:苏宁易购、京东、 天猫、小米商城

3、C2B模式 C2B(CustomertoBusiness)

即消费者对企业。先有消费者需求产生而后有企业生产,即先 有消费者提出需求,后有生产企业按需求组织生产

4、C2C模式 C2C (Customer to Consumer)

客户之间自己把东西放上网去卖,如:淘宝,闲鱼

5、O2O模式 O2O即Online To Ofline

也即将线下商务的机会与互联网结合在了一起,让互联网成为线 下交易的前台。线上快速支付,线下优质服务。如:饿了么,美团,淘票票,京东到家

技术栈

  • 前端 html css js jquery freemarker vue

  • 基础 javaSE javaEE

  • 框架 spring springMVC springBoot mybatis mybatis-plus

  • 安全 shiro(spring security)

  • 微服务 springCloud springCloud alibaba

  • 数据库 mysql

  • 测试 junit jmeter

项目架构图

SpringCloud微服务系统架构图 zmall

 模块

模块名端口名称说明
zmall-common公共
zmall-user8010用户服务
zmall-product8020产品服务
zmall-cart8030购物车服务
zmall-order8040订单服务
zmall-play8050支付服务
zmall-kill8060秒杀服务
zmall-gateway8000网关服务

案例演示

主模块

1.在idea中基于maven方式创建主模块zmall,创建成功之后删除src目录即可。

2.配置主模块pom.xml  

2.1 依赖版本锁定

<!--依赖版本的锁定-->
<properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <spring-boot.version>2.3.2.RELEASE</spring-boot.version>
    <spring-cloud.version>Hoxton.SR9</spring-cloud.version>
    <spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>
</properties>

2.2 dependencyManagement配置

<dependencyManagement>
	<dependencies>
        <!-- SpringBoot 依赖配置 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    	<!--spring-cloud依赖配置-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!--spring-cloud-alibaba依赖配置-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${spring-cloud-alibaba.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

2.3 子模块定义(目前还没有这两个子模块,先不要定义

<modules>
    <module>zmall-common</module>
    <module>zmall-user</module>
</modules>

2.4 设置maven编译版本

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

 zmall-common子模块

  1. 基于maven方式创建zmall-common公共子模块。注:zmall-common公共模块只为其他模块提供依赖支持。

    自动加进来了子模块 

  2. 配置pom.xml(公共模块需要导入每一个项目中可能会需要用到的依赖

    <dependencies>
            <!-- mybatis plus依赖 -->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>3.4.0</version>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.44</version>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.56</version>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-freemarker</artifactId>
            </dependency>
    </dependencies>

zmall-user子模块

1.基于Spring Initialzr方式创建zmall-user用户模块

Maven项目可以主动选择父模块,而Springboot项目则需要手动选择

2.配置pom.xml。设置父模块,并添加zmall-common公共模块的依赖支持。

<!-- 父模块 -->
<parent>
    <groupId>com.zking.zmall</groupId>
    <artifactId>zmall</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
    <dependency>
        <groupId>com.zking.zmall</groupId>
        <artifactId>zmall-common</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

 3.添加登录页面及公共资源

1)将资料目录中的《网页素材.zip》解压后,将其中login.html和js/css/images等等添加到项目的templates和static目录下

2)导入资料目录中的common目录到项目的templates目录下

3)在login.html页面中的头部申明<!DOCTYPE html ....>修改成<!DOCTYPE html>(支持H5风格,因为默认是HTHL4的

4)在login.html页面中通过<#include>指令引入common目录中的head.html

 5)创建UserController并定义login.html页面跳转方式

@Controller
public class UserController {

    @RequestMapping("/login.html")
    public String login(){
        return "login";
    }
}

4.配置application.yml

server:
  port: 8010
spring:
  application:
    name: zmall-user
  datasource:
    #type连接池类型 DBCP,C3P0,Hikari,Druid,默认为Hikari,HikariDataSource属于Mybatisplus依赖
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/zmall?useUnicode=true&characterEncoding=UTF-8&useSSL=false
    username: root
    password: 123
  freemarker: #配置freemarker的访问地址找到templates/下面以.html结尾的文件
    suffix: .html
    template-loader-path: classpath:/templates/

要将表与数据库准备好,数据库名与application.yml中数据库连接相匹配

 运行时将test文件删掉,不然启动会报错,因为我们jar包依赖里没有test,目前还用不到

 运行结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

歐陽。

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值