SpringBoot构建电商基础秒杀项目
视频地址 https://www.imooc.com/video/18332
springboot项目搭建
创建Maven项目
maven-archetype-quickstart
不用springboot可以说使用maven-archetype-webapp,生成项目可以打包成war发布到容器
vuejs版本 https://gitee.com/349032805/miaosha-all
https://gitee.com/robei/miaosha https://github.com/hongjun500/miaosha
spring官方rest例子 https://spring.io/guides/gs/rest-service/
默认配置
resources目录下application.properties
server.port=8080
整合Mybatis
dependency:
数据库驱动 数据库连接池 如druid
com.alibaba
druid
org.mybatis.spring.boot
mybatis-spring-boot-starter
配置文件
mybatis.mapperLocations=classpath:mapping/*.xml spring.datasource.name= spring.dataourse.url= spring.datasource.username= spring.datasource.password=
spring.datasource.type=com.alibaba.druid.poll.DruidDataSource spring.datasource.driverClassName=
mapping创建在resources目录下
@MapperScan("com.xxxx.xxx")
mybatis自动生成器插件
mybatis-generator.xml
数据库设计
register_mode 注册方式 thrid_party_id 第三方id 密码跟用户主表分开存取
使用SpringMVC开发用户信息
service下model目录
controller下创建viewobject目录
BeanUtils.copyProperties(source, targert)
通用返回对象 error目录 enum EmBusinessError implements CommonError // 通用错误类型00001 PARAMETER_VALIDATION_ERROR(00001, "参数不合法") USER_NOT_EXIST(10001, “用户不存在”); int errCode String errMsg
秒杀模块
joda-time jar包
class PromoModel
Integer id
// 1 未开始 2 进行中 3 已结束
Integer status
// 秒杀活动名
String promoName
DateTime startDate
DateTime endDate
Integer itemId
// 秒杀活动商品价格
BigDecimal promoItemPrice