- 1、数据库设计
- 1.1 数据库表关系
- 1.2 表的建立
- 2、前后端接口设计
- 2.1 用户登录
- 2.2 用户注册
- 2.3 查询抽奖设置
- 2.4 修改抽奖人数
- 2.5 新增奖项
- 2.6 修改奖项
- 2.7 删除奖项
- 2.8 新增抽奖人员
- 2.9 修改抽奖人员
- 2.10 删除抽奖人员
- 2.11 抽奖
- 2.12 删除当前奖项某个获奖人员
- 2.13 删除当前奖项全部获奖人员
- 3、开发环境准备
- 3.1 配置项目pom.xml
- 3.2 Springboot配置文件
- 3.3 SpringBoot启动类
1、数据库设计 1.1 数据库表关系 1.2 表的建立
drop database if exists lucky_draw;
create database lucky_draw character set utf8mb4;
use lucky_draw;
drop table if exists user;
create table user(
id int primary key auto_increment,
username varchar(20) not null unique comment '用户账号',
password varchar(20) not null comment '密码',
nickname varchar(20) comment '用户昵称',
email varchar(50) comment '邮箱',
age int comment '年龄',
head varchar(255) comment '头像url',
create_time timestamp default NOW() comment '创建时间'
) comment '用户表';
drop table if exists setting;
create table setting(
id int primary key auto_increment,
user_id int not null comment '用户id',
batch_number int not null comment '每次抽奖人数',
create_time timestamp default NOW() comment '创建时间',
foreign key (user_id) references user(id)
) comment '抽奖设置';
drop table if exists award;
create table award(
id int primary key auto_increment,
name varchar(20) not null comment '奖项名称',
count int not null comment '奖项人数',
award varchar(20) not null comment '奖品',
setting_id int not null comment '抽奖设置id',
create_time timestamp default NOW() comment '创建时间',
foreign key (setting_id) references setting(id)
) comment '奖项';
drop table if exists member;
create table member(
id int primary key auto_increment,
name varchar(20) not null comment '姓名',
no varchar(20) not null comment '工号',
setting_id int not null comment '抽奖设置id',
create_time timestamp default NOW() comment '创建时间',
foreign key (setting_id) references setting(id)
) comment '抽奖人员';
drop table if exists record;
create table record(
id int primary key auto_increment,
member_id int not null comment '中奖人员id',
award_id int not null comment '中奖奖项id',
create_time timestamp default NOW() comment '创建时间',
foreign key (member_id) references member(id),
foreign key (award_id) references award(id)
) comment '中奖记录';
2、前后端接口设计
2.1 用户登录
请求:POST api/user/login
Content-Type: application/json
{username: "abc", password: "123"}
响应:
{ "success" : true }
2.2 用户注册
请求:POST api/user/register
Content-Type: multipart/form-data; boundary=---- WebKitFormBoundarypOUwkGIMUyL0aOZT username: abc password: 123 nickname: 权志龙 email: 666@163.com age: 66 headFile: (binary)
响应:
{ "success" : true }
2.3 查询抽奖设置
请求:GET api/setting/query
响应:
{
"success" : true,
"data" : {
"id" : 1,
"userId" : 1,
"batchNumber" : 8,
"createTime" : "2020-08-14 08:16:31",
"user" : {
"id" : 1,
"username" : "123",
"password" : "123",
"nickname" : "蜡笔小新",
"email" : "1111@163.com",
"age" : 18,
"head" : "img/test-head.jpg",
"createTime" : "2020-08-14 08:16:31",
"settingId" : 1
},
"awards" : [ {
"id" : 1,
"name" : "一等奖",
"count" : 1,
"award" : "火箭",
"settingId" : 1,
"createTime" : "2020-08-14 08:16:31",
"luckyMemberIds" : [ 5 ]
}, {
"id" : 2,
"name" : "二等奖",
"count" : 5,
"award" : "红旗 H5",
"settingId" : 1,
"createTime" : "2020-08-14 08:16:31",
"luckyMemberIds" : [ 56, 40, 32, 65, 81 ]
}, {
"id" : 3,
"name" : "三等奖",
"count" : 20,
"award" : "国内任意游",
"settingId" : 1,
"createTime" : "2020-08-14 08:16:31",
"luckyMemberIds" : [ 48, 68, 43, 73, 13, 83, 63, 25 ]
} ],
"members" : [ {
"id" : 1,
"name" : "李寻欢",
"no" : "水果刀",
"userId" : 1,
"createTime" : "2020-08-14 08:16:31"
}, {
"id" : 2,
"name" : "郭靖",
"no" : "降猪十八掌",
"userId" : 1,
"createTime" : "2020-08-14 08:16:31"
}, {
"id" : 3,
"name" : "韦小宝",
"no" : "龙爪手",
"userId" : 1,
"createTime" : "2020-08-14 08:16:31"
} ]
}
}
2.4 修改抽奖人数
请求:GET api/setting/update?batchNumber=5
响应:
{ "success" : true }
2.5 新增奖项
请求:POST api/award/add
Content-Type: application/json
{name: "牛哄哄", count: 3, award: "华为手机"}
响应:
{ "success" : true }
2.6 修改奖项
请求:POST api/award/update
Content-Type: application/json
{name: "牛哄哄", count: 3, award: "小米手机", id: 4}
响应:
{ "success" : true }
2.7 删除奖项
请求:GET api/award/delete/4
响应:
{ "success" : true }
2.8 新增抽奖人员
请求:POST api/member/add
Content-Type: application/json
{name: "羞羞的粉拳", no: "007"}
响应:
{ "success" : true }
2.9 修改抽奖人员
请求:POST api/member/update
Content-Type: application/json
{name: "泰山", no: "000", id: 96}
响应:
{ "success" : true }
2.10 删除抽奖人员
请求:GET api/member/delete/97
响应:
{ "success" : true }
2.11 抽奖
请求:POST api/record/add/3
Content-Type: application/json [92, 22, 43, 76]
响应:
{ "success" : true }
2.12 删除当前奖项某个获奖人员
请求:GET api/record/delete/member?id=22
响应:
{ "success" : true }
2.13 删除当前奖项全部获奖人员
请求:GET api/record/delete/award?id=3
响应:
{ "success" : true }
3、开发环境准备
3.1 配置项目pom.xml
3.2 Springboot配置文件4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.5.RELEASE org.example lucky-draw 1.0-SNAPSHOT 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat org.springframework.boot spring-boot-starter-undertow org.springframework.boot spring-boot-starter-aop org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.3 org.mybatis.generator mybatis-generator-core 1.3.5 com.alibaba druid-spring-boot-starter 1.2.3 mysql mysql-connector-java 5.1.49 runtime org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin maven-clean-plugin 3.1.0 maven-compiler-plugin 3.8.1 maven-deploy-plugin 2.8.2 maven-install-plugin 2.5.2 maven-jar-plugin 3.2.0 maven-resources-plugin 3.1.0 maven-site-plugin 3.3 maven-surefire-plugin 2.22.2
server.port=8085
debug=true
# 设置打印日志的级别,及打印sql语句
#日志级别:trace,debug,info,warn,error
#基本日志
logging.level.root=INFO
#扫描的包:druid.sql.Statement类和frank包
logging.level.druid.sql.Statement=DEBUG
logging.level.org.example=DEBUG
# 美化JSON数据格式
spring.jackson.serialization.indent-output=true
# 设置JSON数据的日期格式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
# JSON数据属性为null时不返回
spring.jackson.default-property-inclusion=non_null
# get请求参数及表单提交数据的日期格式
spring.mvc.format.date=yyyy-MM-dd HH:mm:ss
#servlet上下文路径
#server.servlet.context-path=/lucky-draw
# 自定义属性:用户头像本地保存根路径
user.head.local-path=E:/TMP
user.head.remote-path=http://localhost:8080${server.servlet.context-path:}
#user.head.filename=head.jpg
# 静态资源映射:将路径映射为/,即/static/xxx,映射为/xxx,支持多个字符串,逗号间隔
# 默认为/META-INF/resources/, /resources/, /static/, /public/
# 指定外部web资源文件夹:访问的路径为/
spring.resources.static-locations=classpath:/static/,classpath:/public/,file:${user.head.local-path}
#druid数据库连接池配置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/lucky_draw?useUnicode=true&characterEncoding=UTF-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.druid.initial-size=1
spring.datasource.druid.min-idle=1
spring.datasource.druid.max-active=20
spring.datasource.druid.test-on-borrow=true
#指定Mybatis表和实体映射关系xml配置文件,包含表与实体的映射,字段和属性的映射,及各个sql语句
mybatis.mapper-locations=classpath:mapper/**Mapper.xml
3.3 SpringBoot启动类
package org.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}



