一、创立数据库表
微信点餐零碎一共须要5个表。
- 商品表:商品编号、商品名称、商品价格、商品库存、商品形容、商品图片、商品状况(上架还是下架)、它属于哪个类目(热销?男生必备?减肥必备等等)、创立工夫、更新工夫。
- 类目表:类目id、类目名、类目类型、创立工夫、更新工夫。
- 订单表:订单编号、买家名字、买家电话、买家地址、买家微信id、订单总金额、订单状态、领取状态、创立工夫、更新工夫。
- 订单详表:信息编号、订单编号、商品编号、商品名、商品价格、商品数量、商品图片、创立工夫、更新工夫。
卖家表:卖家编号、卖家名称、卖家明码、卖家微信id、创立工夫、更新工夫。
临时须要这么多表,别离对商品、订单还有后盾须要应用的卖家详细信息表。
-- 类目create table `product_category` ( `category_id` int not null auto_increment, `category_name` varchar(64) not null comment '类目名字', `category_type` int not null comment '类目编号', `create_time` timestamp not null default current_timestamp comment '创立工夫', `update_time` timestamp not null default current_timestamp on update current_timestamp comment '批改工夫', primary key (`category_id`), UNIQUE KEY `uqe_category_type` (`category_type`));-- 商品create table `product_info` ( `product_id` varchar(32) not null, `product_name` varchar(64) not null comment '商品名称', `product_price` decimal(8,2) not null comment '单价', `product_stock` int not null comment '库存', `product_description` varchar(64) comment '形容', `product_icon` varchar(512) comment '小图', `product_status` tinyint(3) DEFAULT '0' COMMENT '商品状态,0失常1下架', `category_type` int not null comment '类目编号', `create_time` timestamp not null default current_timestamp comment '创立工夫', `update_time` timestamp not null default current_timestamp on update current_timestamp comment '批改工夫', primary key (`product_id`));-- 订单create table `order_master` ( `order_id` varchar(32) not null, `buyer_name` varchar(32) not null comment '买家名字', `buyer_phone` varchar(32) not null comment '买家电话', `buyer_address` varchar(128) not null comment '买家地址', `buyer_openid` varchar(64) not null comment '买家微信openid', `order_amount` decimal(8,2) not null comment '订单总金额', `order_status` tinyint(3) not null default '0' comment '订单状态, 默认为新下单', `pay_status` tinyint(3) not null default '0' comment '领取状态, 默认未领取', `create_time` timestamp not null default current_timestamp comment '创立工夫', `update_time` timestamp not null default current_timestamp on update current_timestamp comment '批改工夫', primary key (`order_id`), key `idx_buyer_openid` (`buyer_openid`));-- 订单商品create table `order_detail` ( `detail_id` varchar(32) not null, `order_id` varchar(32) not null, `product_id` varchar(32) not null, `product_name` varchar(64) not null comment '商品名称', `product_price` decimal(8,2) not null comment '以后价格,单位分', `product_quantity` int not null comment '数量', `product_icon` varchar(512) comment '小图', `create_time` timestamp not null default current_timestamp comment '创立工夫', `update_time` timestamp not null default current_timestamp on update current_timestamp comment '批改工夫', primary key (`detail_id`), key `idx_order_id` (`order_id`));-- 卖家(登录后盾应用, 卖家登录之后可能间接采纳微信扫码登录,不应用账号密码)create table `seller_info` ( `seller_id` varchar(32) not null, `username` varchar(32) not null, `password` varchar(32) not null, `openid` varchar(64) not null comment '微信openid', `create_time` timestamp not null default current_timestamp comment '创立工夫', `update_time` timestamp not null default current_timestamp on update current_timestamp comment '批改工夫', primary key (`seller_id`)) comment '卖家信息表';
二、搭建运行的环境
1、进行环境的配置
创立完表之后,须要应用Mysql、Idea、Nginx等等,这些都在Linux零碎中应用。老师给了一个centos7,装置后即可应用。先下载一个VirtualBox,引入后应用centos7。应用IDEA创立我的项目。创立SpringBoot我的项目,抉择web模块。
2、依赖配置
这里先把相干依赖引入。应用jpa来操作数据。
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-test</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency></dependencies><build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins></build>
3、配置数据库的相干信息
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver username: root password: 123456 url: jdbc:mysql://192.168.1.11:3306/sell?characterEncoding=utf-8&userSSL=false jpa: show-sql: true
因为应用jpa,所以把show-sql关上,mysql引入的是8版本当前的,所以要应用cj下的Driver。
4、日志配置
日志能够配在yaml或properties中,然而这样有个局限,只能配置一部分,当想配置更为简单的日志配置,就没法满足要求。
所以应用logback-spring.xml做日志配置。
<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern> %d -%msg%n </pattern> </layout> </appender> <!--因为这个日志要每天输入,所以是一个滚动的文件--> <!--想让这里只输入失常的日志--> <appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> <level>WARN</level> <onMatch>DENY</onMatch> <onMismatch>ACCEPT</onMismatch> </filter> <encoder> <pattern> %msg%n </pattern> </encoder> <!--配置滚动策略--> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!--配置门路--> <fileNamePattern>D:\LearningTest\mealOrderSystem\TestLog\info.%d.log</fileNamePattern> </rollingPolicy> </appender> <!--这里输入谬误的日志--> <appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>ERROR</level> </filter> <encoder> <pattern> %msg%n </pattern> </encoder> <!--配置滚动策略--> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!--配置门路--> <fileNamePattern>D:\LearningTest\mealOrderSystem\TestLog\error.%d.log</fileNamePattern> </rollingPolicy> </appender> <root level="info"> <appender-ref ref="consoleLog"/> <appender-ref ref="fileInfoLog"/> <appender-ref ref="fileErrorLog"/> </root><?xml version="1.0" encoding="UTF-8" ?><configuration> <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern> %d -%msg%n </pattern> </layout> </appender> <!--因为这个日志要每天输入,所以是一个滚动的文件--> <!--想让这里只输入失常的日志--> <appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> <level>WARN</level> <onMatch>DENY</onMatch> <onMismatch>ACCEPT</onMismatch> </filter> <encoder> <pattern> %msg%n </pattern> </encoder> <!--配置滚动策略--> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!--配置门路--> <fileNamePattern>D:\LearningTest\mealOrderSystem\TestLog\info.%d.log</fileNamePattern> </rollingPolicy> </appender> <!--这里输入谬误的日志--> <appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>ERROR</level> </filter> <encoder> <pattern> %msg%n </pattern> </encoder> <!--配置滚动策略--> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!--配置门路--> <fileNamePattern>D:\LearningTest\mealOrderSystem\TestLog\error.%d.log</fileNamePattern> </rollingPolicy> </appender> <root level="info"> <appender-ref ref="consoleLog"/> <appender-ref ref="fileInfoLog"/> <appender-ref ref="fileErrorLog"/> </root></configuration>
这样就能够生成查看信息和错误报告的文件了。