3、后端项目搭建

项目结构搭建

1、使用Spring Intitializr创建模块

  • Project Metadata
    • Group: com.jd.gulimall
    • Artifact: mall-product
    • Package: com.jd.mall.product
  • Dependencies添加依赖
    • Web-Spring Web
    • Spring Cloud Routing-OpenFeign

2、创建以下几个微服务模块

  • mall-coupon(优惠卷服务)
  • mall-member(会员服务)
  • mall-order(订单服务)
  • mall-product(商品服务)
  • mall-ware(仓储服务)

3、创建主pom.xml文件整合微服务

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.jd.mall</groupId>
    <artifactId>mall</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mall</name>
    <description>聚合服务</description>
    <packaging>pom</packaging>

    <modules>
        <module>mall-coupon</module>
        <module>mall-member</module>
        <module>mall-order</module>
        <module>mall-product</module>
        <module>mall-ware</module>
        <module>renren-fast</module>
        <module>renren-generator</module>
        <module>mall-common</module>
    </modules>
</project>

4、修改.gitignore文件

target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

**/mvnw
**/mvnw.cmd

**/.mvn
**/target/

.idea

**/.gitignore
数据库初始化

mall-coupon(优惠卷服务)–>gulimall_sms
mall-member(会员服务) -->gulimall_ums
mall-order(订单服务) -->gulimall_oms
mall-product(商品服务) -->gulimall_pms
mall-ware(仓储服务) -->gulimall_wms

后台管理系统搭建

1、人人开源 / renren-fast

git clone [email protected]:renrenio/renren-fast.git

2、添加主pom.xml文件管理

<modules>
    <module>renren-fast</module>
</modules>

3、创建数据库gulimall_admin
4、修改参数配置文件(application-dev.yml)

spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
            driver-class-name: com.mysql.cj.jdbc.Driver
            url: jdbc:mysql://192.168.56.10:3306/gulimall_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
            username: root
            password: root
            initial-size: 10
            max-active: 100
            min-idle: 10
            max-wait: 60000
            pool-prepared-statements: true
            max-pool-prepared-statement-per-connection-size: 20
            time-between-eviction-runs-millis: 60000
            min-evictable-idle-time-millis: 300000
逆向工程代码生成器

1、 人人开源 / renren-generator

git clone [email protected]:renrenio/renren-generator.git

2、添加主pom.xml文件管理

<modules>
    <module>renren-generator</module>
</modules>

3、 改配置文件数据库连接(application.yml)

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    #MySQL配置
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://192.168.56.10:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: root

5、修改生成文件属性配置(generator.properties)

mainPath=com.jd
#包名
package=com.jd.mall
moduleName=product
#作者
author=XXX
#Email
[email protected]
#表前?(?名不包含表前?)
tablePrefix=pms_

6、运行逆向工程,将相应微服务模块main文件夹替换成生成的main文件夹

  • 创建com.jd.common.utils,从renren-fast的io.renren.common.utils拷贝

    • com.jd.common.utils.Constant
    • com.jd.common.utils.PageUtils
    • com.jd.common.utils.Query
    • com.jd.common.utils.R
    • com.jd.common.utils.RRException
  • 创建com.atguigu.common.xss,从renren-fast的io.renren.common.xss拷贝

  • com.atguigu.common.xss.HTMLFilter

  • com.atguigu.common.xss.SQLFilter

测试商品微服务模块基本CRUD

1、整合MyBatis-Plus
(1)mall-common导入依赖

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.3.1</version>
</dependency>

(2)配置数据源

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.17</version>
</dependency>
  • 在application.yml配置数据源相关信息
spring:
  datasource:
    username: root
    password: root
    url: jdbc:mysql://192.168.56.10:3306/gulimall_pms
    driver-class-name: com.mysql.jdbc.Driver
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
      config:
        server-addr: 127.0.0.1:8848
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss


mybatis-plus:
  mapper-locations: classpath:/mapper/**/*.xml
  global-config:
    db-config:
      id-type: auto
      logic-delete-value: 1 # 逻辑已删除值(默认为 1)
      logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
server:
  port: 10000
logging:
  level:
    com.jd.mall: debug #打印sql
使用以上同样的方法分别创建及配置其他微服务模块

猜你喜欢

转载自blog.csdn.net/KAIZ_LEARN/article/details/107664423