SpringBoot构建电商秒杀项目(一) 基础项目的搭建 - Go语言中文社区

SpringBoot构建电商秒杀项目(一) 基础项目的搭建


第一章

1.1 电商秒杀项目介绍

电商秒杀项目介绍

  • 商品列表页获取秒杀商品列表
  • 进入商品详情页获取秒杀商品详情
  • 秒杀开始后进入下单确认页下单并支付成功

1.2 IDEA创建maven项目

以下流程为课程操作,实际也可以在IDEA进行Spring Initial快速配置SpringBoot

  1. new->project->maven项目->选择maven-archetype-quickstart
    1_01

  2. 新建一个resources目录,作为资源文件目录,点击右键,指定为Resource root
    1_02

  3. 引入SpringBoot依赖包实现简单的Web项目

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.1.4.RELEASE</version>
</parent>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>

在pom.xml中引入依赖,启动App,访问localhost:8080

1.3 引入Mybatis

1. 修改application.properties

在SpringBoot的默认配置文件application.properties可以配置数据库连接,引入Mybatis,使用druid数据源

#引入Mybatis
mybatis.mapper-locations=classpath:mapping/*.xml
#数据库配置
spring.datasource.name=miaosha
spring.datasource.url=jdbc:mysql://localhost:3306/miaosha?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=yourpassword
#使用druid数据源
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

2. 引入Plugin插件

<!--自动生成工具,生成数据库文件的映射-->
<plugin>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-maven-plugin</artifactId>
  <version>1.3.5</version>
  <dependencies>
    <dependency>
      <groupId>org.mybatis.generator</groupId>
      <artifactId>mybatis-generator-core</artifactId>
      <version>1.3.5</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.41</version>
    </dependency>
  </dependencies>
  <executions>
    <execution>
      <id>mybatis generator</id>
      <phase>package</phase>
      <goals>
        <goal>generate</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <!--允许移动生成的文件-->
    <verbose>true</verbose>
    <!--允许自动覆盖文件(生产环境中千万不要这样做)-->
    <overwrite>true</overwrite>
    <configurationFile>
      src/main/resources/mybatis-generator.xml
    </configurationFile>
  </configuration>
</plugin>

3. Mybatis generator自动生成器

Mybatis generator自动生成数据库对应的映射文件
引入官方配置xml文件

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE generatorConfiguration

        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"

        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>



    <context id="DB2Tables" targetRuntime="MyBatis3">
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/miaosha?serverTimezone=GMT%2B8"
                        userId="root"
                        password="sxy123">

        </jdbcConnection>

        <!-- 生成DataObject类存放位置 -->

        <javaModelGenerator targetPackage="com.miaoshaproject.dataobject" targetProject="src/main/java">

            <property name="enableSubPackages" value="true" />

            <property name="trimStrings" value="true" />

        </javaModelGenerator>

        <!-- 生成映射文件存放位置 -->

        <sqlMapGenerator targetPackage="mapping"  targetProject="src/main/resources">

            <property name="enableSubPackages" value="true" />

        </sqlMapGenerator>

        <!-- 生成Dao类存放位置 -->

        <!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件的代码

              type="ANNOTATIONDMAPPER",生成Java Model和基于注解的Mapper 对象

              type="MIXEDMAPPER",生成基于注解的Java Model和相应的Mapper对象

              type="XMLMAPPER",生成SQLMap XML 文件和独立的Mapper接口

         -->

        <javaClientGenerator type="XMLMAPPER" targetPackage="com.miaoshaproject.dao"  targetProject="src/main/java">

            <property name="enableSubPackages" value="true" />

        </javaClientGenerator>


        <!--生成对应表及类名-->
        <!--<table  tableName="user_info" domainObjectName="UserDO" enableCountByExample="false"
        enableUpdateByExample="false" enableDeleteByExample="false"
        enableSelectByExample="false" selectByExampleQueryId="false"></table>

        <table  tableName="user_password" domainObjectName="UserPasswordDO" enableCountByExample="false"
                enableUpdateByExample="false" enableDeleteByExample="false"
                enableSelectByExample="false" selectByExampleQueryId="false"></table>

        <table  tableName="item" domainObjectName="ItemDO" enableCountByExample="false"
                enableUpdateByExample="false" enableDeleteByExample="false"
                enableSelectByExample="false" selectByExampleQueryId="false"></table>

        <table  tableName="item_stock" domainObjectName="ItemStockDO" enableCountByExample="false"
                enableUpdateByExample="false" enableDeleteByExample="false"
                enableSelectByExample="false" selectByExampleQueryId="false"></table>

        <table  tableName="order_info" domainObjectName="OrderDO" enableCountByExample="false"
                enableUpdateByExample="false" enableDeleteByExample="false"
                enableSelectByExample="false" selectByExampleQueryId="false"></table>

        <table  tableName="sequence_info" domainObjectName="SequenceDO" enableCountByExample="false"
                enableUpdateByExample="false" enableDeleteByExample="false"
                enableSelectByExample="false" selectByExampleQueryId="false"></table>
        -->
        <table  tableName="promo" domainObjectName="PromoDO" enableCountByExample="false"
                enableUpdateByExample="false" enableDeleteByExample="false"
                enableSelectByExample="false" selectByExampleQueryId="false"></table>
    </context>

</generatorConfiguration>

—————————————————————————————————
【系列笔记已经更新完毕】

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_35580701/article/details/104852113
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-04-11 09:44:34
  • 阅读 ( 925 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢