SpringBoot實戰——微信點餐系統


1、初始化項目

  引入模塊

  

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

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

2、application.properties

 (1)改成application.yml,yml可讀性較強 編輯較為簡單

 (2)添加數據庫配置

  

spring:
  datasource:
    url: http://localhost:3036/sell?useUnicode=true&&characterEncoding=utf-8
    driver-class-name: com.mysql.jdbc.Driver
    username: root
    password: root
  jpa:
    show-sql: true
  freemarker:
    allow-request-override: false
    cache: false
    check-template-location: true
    charset: utf-8
    content-type: text/html
    suffix: .ftl
    template-loader-path: classpath:/templates/

3、創建數據庫

CREATE TABLE `order_detail` (
  `detail_id` varchar(32) NOT NULL,
  `order_id` varchar(32) NOT NULL,
  `product_id` varchar(32) NOT NULL COMMENT '商品id',
  `product_name` varchar(32) NOT NULL COMMENT '商品名稱',
  `product_price` decimal(8,2) NOT NULL COMMENT '商品價格',
  `prodiuct_quantity` int(11) NOT NULL COMMENT '商品數量',
  `product_icon` varchar(512) DEFAULT 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`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 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(32) NOT NULL COMMENT '買家地址',
  `buyer_openid` varchar(64) NOT NULL COMMENT '買家微信openId',
  `buyer_amount` decimal(8,2) NOT NULL COMMENT '訂單總額',
  `buyer_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`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='訂單表';

CREATE TABLE `product_category` (
  `category_id` int(11) NOT NULL AUTO_INCREMENT,
  `category_name` varchar(64) NOT NULL COMMENT '類別名稱',
  `category_type` int(11) NOT NULL COMMENT '類名編號',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '創建時間',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改時間',
  PRIMARY KEY (`category_id`),
  UNIQUE KEY `uqe_category_type` (`category_type`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='類別表';

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(11) NOT NULL COMMENT '庫存',
  `product_description` varchar(64) DEFAULT NULL COMMENT '描述',
  `product_icon` varchar(512) DEFAULT NULL COMMENT '圖標',
  `product_type` int(11) 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`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='產品表';

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM