Wechat ordering system 01 - environment construction
1, Create database table
Wechat ordering system requires a total of 5 tables.
-
Commodity list: commodity number, commodity name, commodity price, commodity inventory, commodity description, commodity picture, commodity condition (on or off the shelf), which category it belongs to (hot sale? Necessary for boys? Necessary for weight loss, etc.), creation time and update time.
-
Category table: category id, category name, category type, creation time and update time.
-
Order form: order number, buyer's name, buyer's telephone number, buyer's address, buyer's wechat id, total order amount, order status, payment status, creation time and update time.
-
Order details: information number, order number, commodity number, commodity name, commodity price, commodity quantity, commodity picture, creation time and update time.
-
Seller table: seller number, seller name, seller password, seller wechat id, creation time and update time.
So many tables are needed for the time being, including the detailed information table of goods, orders and sellers that need to be used in the background.
-- Category create table `product_category` ( `category_id` int not null auto_increment, `category_name` varchar(64) not null comment 'Category name', `category_type` int not null comment 'Category number', `create_time` timestamp not null default current_timestamp comment 'Creation time', `update_time` timestamp not null default current_timestamp on update current_timestamp comment 'Modification time', primary key (`category_id`), UNIQUE KEY `uqe_category_type` (`category_type`) ); -- commodity create table `product_info` ( `product_id` varchar(32) not null, `product_name` varchar(64) not null comment 'Trade name', `product_price` decimal(8,2) not null comment 'Unit Price', `product_stock` int not null comment 'stock', `product_description` varchar(64) comment 'describe', `product_icon` varchar(512) comment 'Small picture', `product_status` tinyint(3) DEFAULT '0' COMMENT 'Commodity status,0 Normal 1 off the shelf', `category_type` int not null comment 'Category number', `create_time` timestamp not null default current_timestamp comment 'Creation time', `update_time` timestamp not null default current_timestamp on update current_timestamp comment 'Modification time', primary key (`product_id`) ); -- order create table `order_master` ( `order_id` varchar(32) not null, `buyer_name` varchar(32) not null comment 'Buyer name', `buyer_phone` varchar(32) not null comment 'Buyer telephone', `buyer_address` varchar(128) not null comment 'Buyer address', `buyer_openid` varchar(64) not null comment 'Buyer wechat openid', `order_amount` decimal(8,2) not null comment 'Total order amount', `order_status` tinyint(3) not null default '0' comment 'Order status, Default to new order', `pay_status` tinyint(3) not null default '0' comment 'Payment status, Default unpaid', `create_time` timestamp not null default current_timestamp comment 'Creation time', `update_time` timestamp not null default current_timestamp on update current_timestamp comment 'Modification time', primary key (`order_id`), key `idx_buyer_openid` (`buyer_openid`) ); -- Order goods 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 'Trade name', `product_price` decimal(8,2) not null comment 'Current price,Unit score', `product_quantity` int not null comment 'quantity', `product_icon` varchar(512) comment 'Small picture', `create_time` timestamp not null default current_timestamp comment 'Creation time', `update_time` timestamp not null default current_timestamp on update current_timestamp comment 'Modification time', primary key (`detail_id`), key `idx_order_id` (`order_id`) ); -- seller(Login background use, After logging in, the seller may directly log in by scanning the wechat code without using the account password) 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 'WeChat openid', `create_time` timestamp not null default current_timestamp comment 'Creation time', `update_time` timestamp not null default current_timestamp on update current_timestamp comment 'Modification time', primary key (`seller_id`) ) comment 'Seller information sheet';
2, Build an environment for operation
1. Configure the environment
After creating the table, you need to use Mysql, idea, Nginx, etc., which are all used in Linux system. The teacher gave a centos7, which can be used after installation. Download a VirtualBox first and use centos7 after introduction. Create a project using idea. Create the SpringBoot project and select the web module.
2. Dependency configuration
Here we first introduce the related dependencies. Use jpa to manipulate data.
<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. Information about the configuration database
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
Because jpa is used, open show SQL. mysql is introduced after version 8, so use the Driver under cj.
4. Log configuration
Logs can be configured in yaml or properties, but there is a limitation. Only a part can be configured. When you want to configure more complex log configurations, you can't meet the requirements.
So use logback spring XML for log configuration.
<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern> %d -%msg%n </pattern> </layout> </appender> <!--Because this log needs to be output every day, it is a rolling file--> <!--Want to output only normal logs here--> <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> <!--Configure scrolling policy--> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!--Configuration path--> <fileNamePattern>D:\LearningTest\mealOrderSystem\TestLog\info.%d.log</fileNamePattern> </rollingPolicy> </appender> <!--The error log is output here--> <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> <!--Configure scrolling policy--> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!--Configuration path--> <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> <!--Because this log needs to be output every day, it is a rolling file--> <!--Want to output only normal logs here--> <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> <!--Configure scrolling policy--> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!--Configuration path--> <fileNamePattern>D:\LearningTest\mealOrderSystem\TestLog\info.%d.log</fileNamePattern> </rollingPolicy> </appender> <!--The error log is output here--> <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> <!--Configure scrolling policy--> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!--Configuration path--> <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>
In this way, you can generate files for viewing information and error reports.