当前位置:网站首页>简单秒杀项目简介
简单秒杀项目简介
2022-07-13 17:55:00 【早日拿offer】
通过使用SpringBoot快速搭建前后端分离的电商基础秒杀项目。项目中会通过应用领域驱动型的分层模型设计方式去完成用户otp注册、登陆、查看、商品列表、进入商品详情以及倒计时秒杀开始后下单购买的基本流程。
电商秒杀项目简介:
1、商品列表页获取秒杀商品列表
2、进入商品详情页获取秒杀商品详情
3、秒杀开始后进入下单确认页下单并支付成功
使用SpringBoot完成基础项目搭建
使用IDEA+Maven搭建SpringBoot开发环境。
引入依赖
pom.xml(后续项目所需的所有依赖)
包括springboot的web启动器:spring-boot-starter-web
数据库相关依赖:mysql-connector-join,mybatis-spring-boot-starter等等
<?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.miaoshaproject</groupId>
<artifactId>miaosha</artifactId>
<version>1.0-SNAPSHOT</version>
<name>miaosha</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.5.5</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot </groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.4.Final</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</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 generotor</id>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<!--允许移动生成的文件-->
<verbose>true</verbose>
<!--允许自动覆盖文件-->
<overwrite>false</overwrite>
<configurationFile>
src/main/resources/mybatis-generator.xml
</configurationFile>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
mybatis自动生成器
mybatis-generator.xml:根据数据库的表生成相应的dao,dataobject,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>
<!--驱动包的路径-->
<!--<classPathEntry location="C:\Users\lhf\.m2\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar" />-->
<!--数据库连接-->
<context id="DB2Tables" targetRuntime="MyBatis3">
<!--注释-->
<!--<commentGenerator> <property name="suppressAllComments" value="true"/> <property name="suppressDate" value="true"/> </commentGenerator>-->
<!--数据库连接地址及账号密码-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/miaosha?useSSL=false" userId="root" password="123456">
</jdbcConnection>
<!--<javaTypeResolver > <property name="forceBigDecimals" value="false" /> </javaTypeResolver>-->
<!--生成DataObject类存放位置-->
<javaModelGenerator targetPackage="com.miaoshaproject.dataobject" targetProject="src/main/java">
<!--是否对Model添加构造函数-->
<!--<property name="constructorBased" value="false"/>-->
<!--是否允许子包-->
<property name="enableSubPackages" value="true"/>
<!--建立的model对象是否不可变,也就是生成的model没有setter方法-->
<!--<property name="immutable" value="false"/>-->
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成映射文件存放位置-->
<sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!--生成Dao类的存放位置-->
<!-- 客户端代码,生成易于使用的正对Model对象和XML配置文件的代码 type="ANNOTATEDMAPPER", 生成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 schema="mybatis" tableName="user_info" domainObjectName="UserDO" enableInsert="true" enableSelectByExample="false" enableDeleteByPrimaryKey="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" enableSelectByPrimaryKey="true" enableUpdateByPrimaryKey="true"/>-->
<!--<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>
App类
将App类被spring托管@SpringBootApplication(ScanBasePackage={“com.miaoshaproject”})
package com.miaoshaproject;
import com.miaoshaproject.dao.UserDOMapper;
import com.miaoshaproject.dataobject.UserDO;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** * Hello world! * */
@SpringBootApplication(scanBasePackages= {
"com.miaoshaproject"})
@RestController
@MapperScan("com.miaoshaproject.dao")
public class App
{
@Autowired
private UserDOMapper userDOMapper;
@RequestMapping("/")
public String home() {
UserDO userDO = userDOMapper.selectByPrimaryKey(1);
if(userDO == null) {
return "用户对象不存在";
} else {
return userDO.getName();
}
}
public static void main( String[] args )
{
System.out.println( "Hello World!" );
SpringApplication.run(App.class, args);
}
}
mybatis配置文件
application.properties
注意映射的xml文件地址不出错
server.port=8090
mybatis.mapper-locations=classpath:mapping/*.xml
spring.datasource.name=miaosha
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/miaosha?useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
# 使用druid数据源
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driverClassName=com.mysql.jdbc.Driver
边栏推荐
猜你喜欢

SQL基础1

Chapter VI use of OLED module +stm32

Redis is the fastest to get started in history (attach redis on ECs)
![[cloud native | middleware] open source SPL can easily cope with t+0](/img/52/85fde54c79b6b955964c05d28dbfbb.png)
[cloud native | middleware] open source SPL can easily cope with t+0

SSM library management system
![[introduction to go language] 09 detailed explanation of go language slice](/img/e8/9d2df78a29c15d3564555b85f8a561.png)
[introduction to go language] 09 detailed explanation of go language slice

三分钟上手Markdown——基本语法快速入门

TypeScript基础配置使用教程(在VScode中自动编译)

宝塔面板在同一服务器下创建多个端口部署项目(轻量应用服务器一键部署网站、博客、GltLab完整版)

Pyopencv basic operation guide
随机推荐
I learned JWT single sign on with a cup of tea
01kNN_ Regression
[go language introduction] 13 go language interface details
How to select embedded single chip microcomputer?
【C语言】 大学生考勤管理系统
Leetcode-2 addition of two numbers (head insertion, tail insertion of linked list, addition and subtraction of two linked lists with different lengths)
分布式理论
LeetCode 刷题 第四天
001 空指针和野指针
General commands of MATLAB
[Go语言入门] 05 Go语言分支语句
[HBuilderX开发uniapp]自动代码格式化插件安装及配置
02 featurescaling normalization
Use MessageBox to realize window confession applet (with source code)
LeetCode 刷题 第十天
Pagoda panel creates multiple port deployment projects under the same server (lightweight application server one click deployment website, blog, gltlab full version)
Obsidian third-party plug-in failed to load
JVM annual ecosystem report - 2020
小阶段总结
vant Weapp组件库中 自定义修改van-button 按钮宽高大小