目录
1.数据库表设计
1.1秒杀商品表字段
- 主键
- 商品id
- 标题
- 商品图片
- 原价格
- 秒杀价格
- 商家id
- 添加日期
- 审核日期
- 审核转态
- 开始时间
- 结束时间
- 秒杀商品数
- 剩余库存数
- 描述
1.2秒杀订单表字段
- 主键
- 秒杀商品id
- 支付金额
- 用户id
- 商家id
- 创建时间
- 支付时间
- 支付转态
- 收货人地址
- 收货人电话
- 收货人
- 交易流水号
1.3秒杀商品详情表字段
- 主键
- 商品id
- 商家id
- 商品产地
- 商品名称
- 品牌
- 商品毛重
- 规格和包装
- 商品详情图片地址
1.4秒杀系统用户表字段
- 主键
- 用户姓名
- 用户账号
- 用户密码
- 用户性别
- 用户年龄
- 用户住址
- 用户邮箱
1.5秒杀商家表字段
- 主键
- 商家姓名
- 商家店铺名称
- 商家账号
- 商家密码
- 商家经营范围
1.6建表SQL语句
-
DROP TABLE IF EXISTS `msmerchants`;
-
-
CREATE TABLE `msmerchants` (
-
-
`merchantsid` int(100) NOT NULL AUTO_INCREMENT COMMENT '商家id,主键自动递增',
-
-
`merchantsname` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '商家姓名',
-
-
`merchantsshop` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '商家店铺名称',
-
-
`merchantsaccount` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '商家账号',
-
-
`merchantspassword` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '商家密码',
-
-
`merchantsscope` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '商家的经营范围',
-
-
PRIMARY KEY (`merchantsid`)
-
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-
-
-
-
DROP TABLE IF EXISTS `msorder`;
-
-
CREATE TABLE `msorder` (
-
-
`id` int(100) NOT NULL AUTO_INCREMENT COMMENT '主键,自动递增',
-
-
`productid` int(100) DEFAULT NULL COMMENT '秒杀商品ID',
-
-
`payamount` decimal(10,0) DEFAULT NULL COMMENT '支付金额',
-
-
`userid` int(100) DEFAULT NULL COMMENT '用户ID',
-
-
`merchantsid` int(100) DEFAULT NULL COMMENT '商家ID',
-
-
`creationtime` datetime DEFAULT NULL COMMENT '创建时间',
-
-
`paymenttime` datetime DEFAULT NULL COMMENT '支付时间',
-
-
`paymentstatus` int(5) DEFAULT NULL COMMENT '支付状态,0未支付,1已经支付',
-
-
`consigneeaddress` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '收货人地址',
-
-
`consigneephone` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '收货人电话',
-
-
`consignee` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '收货人',
-
-
`tradeserial` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '交易流水号',
-
-
PRIMARY KEY (`id`)
-
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-
-
-
-
DROP TABLE IF EXISTS `msproduct`;
-
-
CREATE TABLE `msproduct` (
-
-
`id` int(100) NOT NULL AUTO_INCREMENT COMMENT '主键,自动递增',
-
-
`productid` int(100) NOT NULL COMMENT '商品ID',
-
-
`producttitle` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '商品标题',
-
-
`productpicture` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '商品图片',
-
-
`originalprice` decimal(10,0) DEFAULT NULL COMMENT '原价格',
-
-
`msprice` decimal(10,0) DEFAULT NULL COMMENT '秒杀价格',
-
-
`merchantsid` int(100) DEFAULT NULL COMMENT '商家id',
-
-
`adddate` datetime DEFAULT NULL COMMENT '添加日期',
-
-
`auditdate` datetime DEFAULT NULL COMMENT '审核日期',
-
-
`reviewstatus` int(5) DEFAULT NULL COMMENT '审核状态,1通过,0未通过',
-
-
`starttime` datetime DEFAULT NULL COMMENT '开始时间',
-
-
`endtime` datetime DEFAULT NULL COMMENT '结束时间',
-
-
`msproductnumber` int(100) DEFAULT NULL COMMENT '秒杀商品数',
-
-
`remaininginventory` int(100) DEFAULT NULL COMMENT '剩余库存',
-
-
`describe` varchar(555) COLLATE utf8_bin DEFAULT NULL COMMENT '描述',
-
-
PRIMARY KEY (`id`)
-
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-
-
-
-
DROP TABLE IF EXISTS `msproductdetails`;
-
-
CREATE TABLE `msproductdetails` (
-
-
`id` int(100) NOT NULL AUTO_INCREMENT COMMENT '主键,自动递增',
-
-
`productid` int(100) DEFAULT NULL COMMENT '秒杀商品id',
-
-
`merchantsid` int(100) DEFAULT NULL COMMENT '商家ID',
-
-
`productaddress` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '商品产地',
-
-
`productname` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '商品名称',
-
-
`brand` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '品牌',
-
-
`productweight` double(100,0) DEFAULT NULL COMMENT '商品毛重',
-
-
`productpacking` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '规格和包装',
-
-
`imgaddress` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '商品详情图片地址',
-
-
PRIMARY KEY (`id`)
-
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-
-
-
-
DROP TABLE IF EXISTS `msuser`;
-
-
CREATE TABLE `msuser` (
-
-
`userid` int(100) NOT NULL AUTO_INCREMENT COMMENT '主键,用户id自动递增',
-
-
`username` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '用户姓名',
-
-
`useraccount` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '用户账号',
-
-
`userpassword` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '用户密码',
-
-
`usersex` varchar(5) COLLATE utf8_bin DEFAULT NULL COMMENT '用户性别',
-
-
`userage` int(50) DEFAULT NULL COMMENT '用户年龄',
-
-
`useraddress` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '用户住址',
-
-
`useremail` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '用户邮箱',
-
-
PRIMARY KEY (`userid`)
-
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
2.秒杀系统项目搭建
2.1新建maven项目
pom.xml 中添加依赖
-
<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.albertyy</groupId>
-
-
<artifactId>MsProduct</artifactId>
-
-
<version>0.0.1-SNAPSHOT</version>
-
-
<packaging>war</packaging>
-
-
-
-
<dependencies>
-
-
<dependency>
-
-
<groupId>junit</groupId>
-
-
<artifactId>junit</artifactId>
-
-
<version>4.10</version>
-
-
<scope>test</scope>
-
-
</dependency>
-
-
-
-
<!-- 数据源 -->
-
-
<dependency>
-
-
<groupId>commons-dbcp</groupId>
-
-
<artifactId>commons-dbcp</artifactId>
-
-
<version>1.4</version>
-
-
</dependency>
-
-
-
-
<dependency>
-
-
<groupId>mysql</groupId>
-
-
<artifactId>mysql-connector-java</artifactId>
-
-
<version>5.1.38</version>
-
-
</dependency>
-
-
-
-
<!-- Mybatis3.4.1 -->
-
-
<dependency>
-
-
<groupId>org.mybatis</groupId>
-
-
<artifactId>mybatis</artifactId>
-
-
<version>3.4.1</version>
-
-
</dependency>
-
-
-
-
<!-- spring整合mybatis -->
-
-
<dependency>
-
-
<groupId>org.mybatis</groupId>
-
-
<artifactId>mybatis-spring</artifactId>
-
-
<version>1.3.0</version>
-
-
</dependency>
-
-
-
-
<!-- Spring-4.2.0 -->
-
-
<dependency>
-
-
<groupId>org.springframework</groupId>
-
-
<artifactId>spring-web</artifactId>
-
-
<version>4.2.0.RELEASE</version>
-
-
</dependency>
-
-
-
-
<dependency>
-
-
<groupId>org.springframework</groupId>
-
-
<artifactId>spring-orm</artifactId>
-
-
<version>4.2.0.RELEASE</version>
-
-
</dependency>
-
-
-
-
<dependency>
-
-
<groupId>org.springframework</groupId>
-
-
<artifactId>spring-expression</artifactId>
-
-
<version>4.2.0.RELEASE</version>
-
-
</dependency>
-
-
-
-
</dependencies>
-
-
-
-
</project>
2.2添加WEB-INF和web.xml
Web.xml:
-
<?xml version="1.0" encoding="UTF-8"?>
-
-
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
-
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
-
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
-
-
<context-param>
-
-
<param-name>contextConfigLocation</param-name>
-
-
<param-value>
-
-
classpath:application-context.xml
-
-
</param-value>
-
-
</context-param>
-
-
-
-
<filter>
-
-
<filter-name>characterEncodingFilter</filter-name>
-
-
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
-
-
<init-param>
-
-
<param-name>encoding</param-name>
-
-
<param-value>UTF-8</param-value>
-
-
</init-param>
-
-
</filter>
-
-
<filter-mapping>
-
-
<filter-name>characterEncodingFilter</filter-name>
-
-
<url-pattern>/*</url-pattern>
-
-
</filter-mapping>
-
-
-
-
<listener>
-
-
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
-
-
</listener>
-
-
<listener>
-
-
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
-
-
</listener>
-
-
-
-
<servlet>
-
-
<servlet-name>spring</servlet-name>
-
-
<servlet-class>
-
-
org.springframework.web.servlet.DispatcherServlet
-
-
</servlet-class>
-
-
<load-on-startup>1</load-on-startup>
-
-
</servlet>
-
-
-
-
<servlet-mapping>
-
-
<servlet-name>spring</servlet-name>
-
-
<url-pattern>/*</url-pattern>
-
-
</servlet-mapping>
-
-
<display-name>Archetype Created Web Application</display-name>
-
-
</web-app>
2.3添加配置文件
application-context.xml
-
<?xml version="1.0" encoding="UTF-8"?>
-
-
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
-
-
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
-
-
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache"
-
-
xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans
-
-
http://www.springframework.org/schema/beans/spring-beans.xsd
-
-
http://www.springframework.org/schema/aop
-
-
http://www.springframework.org/schema/aop/spring-aop.xsd
-
-
http://www.springframework.org/schema/context
-
-
http://www.springframework.org/schema/context/spring-context.xsd
-
-
http://www.springframework.org/schema/tx
-
-
http://www.springframework.org/schema/tx/spring-tx.xsd
-
-
http://www.springframework.org/schema/cache
-
-
http://www.springframework.org/schema/cache/spring-cache.xsd">
-
-
-
-
<!-- 自动扫描 -->
-
-
<context:component-scan base-package="com.albertyy.*"/>
-
-
<!-- 引入外置文件 -->
-
-
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
-
-
<property name="location" value="classpath:jdbc.properties"/>
-
-
</bean>
-
-
-
-
<!--数据库连接池配置-->
-
-
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
-
-
<property name="driverClassName" value="${jdbc.driverClassName}"/>
-
-
<property name="url" value="${jdbc.url}"/>
-
-
<property name="username" value="${jdbc.username}"/>
-
-
<property name="password" value="${jdbc.password}"/>
-
-
</bean>
-
-
-
-
<!-- spring和MyBatis完美整合 -->
-
-
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
-
-
<!-- 指定数据源 -->
-
-
<property name="dataSource" ref="dataSource"/>
-
-
<!-- 具体指定xml文件,可不配 -->
-
-
<property name="configLocation" value="classpath:mybatis-config.xml"/>
-
-
<!-- 自动扫描mapping.xml文件,**表示迭代查找 ,,也可在mybatis-config.xml中单独指定xml文件 -->
-
-
<property name="mapperLocations" value="classpath:com/albertyy/seckill/dao/xml/PersonDao.xml"/>
-
-
</bean>
-
-
-
-
<!-- 自动扫描dao下的所有dao接口,并实现这些接口,可直接在程序中使用dao接口,不用再获取sqlsession对象 -->
-
-
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
-
-
-
-
<!--
-
-
basePackage 属性是映射器接口文件的包路径。
-
-
你可以使用分号或逗号 作为分隔符设置多于一个的包路径
-
-
-->
-
-
<property name="basePackage" value="com/albertyy/seckill/dao"/>
-
-
<!--
-
-
因为会自动装配 SqlSessionFactory和SqlSessionTemplate
-
-
所以没 有 必 要 去 指 定 SqlSessionFactory或 SqlSessionTemplate
-
-
因此可省略不配置;
-
-
但是,如果你使 用了一个 以上的 DataSource,那么自动装配可能会失效。
-
-
这种 情况下,你可以使用sqlSessionFactoryBeanName或sqlSessionTemplateBeanName属性来设置正确的 bean名称来使用;
-
-
-->
-
-
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
-
-
</bean>
-
-
-
-
<!-- 事务管理器 -->
-
-
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
-
-
<property name="dataSource" ref="dataSource" />
-
-
</bean>
-
-
-
-
<!-- 使用声明式事务 -->
-
-
<tx:annotation-driven transaction-manager="txManager" />
-
-
</beans>
-
jdbc.properties
-
jdbc.driverClassName=com.mysql.jdbc.Driver
-
-
jdbc.url=jdbc:mysql://localhost:3306/mybatis?characterEncoding=UTF-8
-
-
jdbc.username=root
-
-
jdbc.password=123456
mybatis-config.xml
-
<?xml version="1.0" encoding="UTF-8" ?>
-
-
<!DOCTYPE configuration
-
-
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
-
-
"http://mybatis.org/dtd/mybatis-3-config.dtd">
-
-
-
-
<configuration>
-
-
<typeAliases>
-
-
<!-- 别名定义 -->
-
-
<typeAlias type="com.albertyy.seckill.entity.Person" alias="person" />
-
-
</typeAliases>
-
-
-
-
</configuration>
2.4创建包结构
文章来源: albertyang.blog.csdn.net,作者:Albert Yang,版权归原作者所有,如需转载,请联系作者。
原文链接:albertyang.blog.csdn.net/article/details/86766383