SpringBoot微信點餐系統實戰一:環境搭建和數據庫設計

這是【SpringBoot企業微信點餐系統實戰】系列第一篇前端

源碼地址:github.com/cachecats/s…java

SpringBoot 企業微信點餐系統實戰一:環境搭建和數據庫設計mysql

SpringBoot 企業微信點餐系統實戰二:日誌配置、商品類目開發git

SpringBoot 企業微信點餐系統實戰三:商品信息及買家商品api開發github

學習了SpringSpringMVCSpringBoot 以後,是時候開啓一個實戰項目了。web

1、技術棧

項目採用先後端分離的方式,前端由 Vue 構建,後端用 SpringBoot,後端頁面採用 Bootstrap + FreeMarker + JQuery 實現。先後端經過 RESTful 風格接口相連。redis

整體技術框架.png

其中 SpringBoot 涉及到以下技術和知識點: spring

技術棧.png

2、環境搭建

開發工具: IDEA ,Java版本:1.8,數據庫版本:MySql 5.7sql

  1. 打開IDEA,依次點擊 File -> New -> Project,而後最左側項目類型選擇 Spring InitializrProject SDK 選擇 java1.8,其餘的不用動,點擊 Next 進入下一步。 數據庫

    環境搭建1.png

  2. 填寫 GroupArtifact,打包方式 Packaging 選擇 jar,點擊 Next 進入下一步。

    環境搭建2.png

  3. 選擇依賴。本項目是個web工程,因此最左側欄目選 Web,中間欄勾選 Web,點擊 Next 進入下一步。其餘的依賴邊開發邊添加。

    環境搭建3.png

  4. 最後選擇 項目名和項目地址 ,而後點 Finish 便可

    環境搭建4.png

3、pom.xml文件設置

直接給出 pom.xml 代碼吧,都是寫依賴沒啥好說的,直接複製到你項目中就好。

<?xml version="1.0" encoding="UTF-8"?>
<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.solo</groupId>
	<artifactId>takeout</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>takeout</name>
	<description>微信外賣點餐系統</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <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>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.binarywang</groupId>
            <artifactId>weixin-java-mp</artifactId>
            <version>2.7.0</version>
        </dependency>

        <dependency>
            <groupId>cn.springboot</groupId>
            <artifactId>best-pay-sdk</artifactId>
            <version>1.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

複製代碼

若是你是第一次運行 SpringBoot 項目,下載依賴會耗費很長時間。能夠設置阿里的 maven 鏡像,但依賴太多仍是會花一些時間。

4、數據庫設計

1. 項目設計分析

先講一下項目設計 角色分爲兩種,買家(手機端)和賣家(PC端)。整體來講就是買家建立訂單,並能進行修改等管理操做,賣家能夠對訂單管理,也能夠對商品進行管理。以下圖:

功能分析.png

關係圖以下:

關係圖.png

按照角色劃分和功能分析,項目中應該有五張表,它們之間的關係以下:

數據庫表關係說明.png

2. 數據表設計

先建立商品和訂單相關的4張表,直接貼代碼啦

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 '小圖',
	`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`)
) comment '商品表';

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`)
) comment '類目表';

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 '訂單狀態,默認0新下單',
	`pay_status` tinyint(3) not null default '0'comment '支付狀態,默認0未支付',
	`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`)
) comment '訂單主表';

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) 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 (`detail_id`),
	key `idx_order_id` (`order_id`)
) comment '訂單詳情表';
複製代碼

以上就是數據庫設計,直接執行 Sql 語句便可。


環境搭建和數據庫設計就到這裏,下篇文章見

源碼地址:github.com/cachecats/s…

SpringBoot 企業微信點餐系統實戰一:環境搭建和數據庫設計

SpringBoot 企業微信點餐系統實戰二:日誌配置、商品類目開發

SpringBoot 企業微信點餐系統實戰三:商品信息及買家商品api開發

相關文章
相關標籤/搜索