1、初始化项目
引入模块
1<dependencies> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-data-jpa</artifactId> 5 </dependency> 6 <dependency> 7 <groupId>org.springframework.boot</groupId> 8 <artifactId>spring-boot-starter-web</artifactId> 9 </dependency> 10 11 <dependency> 12 <groupId>mysql</groupId> 13 <artifactId>mysql-connector-java</artifactId> 14 <scope>runtime</scope> 15 </dependency> 16 <dependency> 17 <groupId>org.projectlombok</groupId> 18 <artifactId>lombok</artifactId> 19 <optional>true</optional> 20 </dependency> 21 <dependency> 22 <groupId>org.springframework.boot</groupId> 23 <artifactId>spring-boot-starter-test</artifactId> 24 <scope>test</scope> 25 </dependency> 26 </dependencies>
2、application.properties
(1)改成application.yml,yml可读性较强 编辑较为简单
(2)添加数据库配置
1spring: 2 datasource: 3 url: http://localhost:3036/sell?useUnicode=true&&characterEncoding=utf-8 4 driver-class-name: com.mysql.jdbc.Driver 5 username: root 6 password: root 7 jpa: 8 show-sql: true 9 freemarker: 10 allow-request-override: false 11 cache: false 12 check-template-location: true 13 charset: utf-8 14 content-type: text/html 15 suffix: .ftl 16 template-loader-path: classpath:/templates/
3、创建数据库
1CREATE TABLE `order_detail` ( 2 `detail_id` varchar(32) NOT NULL, 3 `order_id` varchar(32) NOT NULL, 4 `product_id` varchar(32) NOT NULL COMMENT '商品id', 5 `product_name` varchar(32) NOT NULL COMMENT '商品名称', 6 `product_price` decimal(8,2) NOT NULL COMMENT '商品价格', 7 `prodiuct_quantity` int(11) NOT NULL COMMENT '商品数量', 8 `product_icon` varchar(512) DEFAULT NULL COMMENT '商品小图', 9 `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', 10 `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', 11 PRIMARY KEY (`detail_id`), 12 KEY `idx_order_id` (`order_id`) 13) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='订单详情表'; 14 15CREATE TABLE `order_master` ( 16 `order_id` varchar(32) NOT NULL, 17 `buyer_name` varchar(32) NOT NULL COMMENT '买家名字', 18 `buyer_phone` varchar(32) NOT NULL COMMENT '买家电话', 19 `buyer_address` varchar(32) NOT NULL COMMENT '买家地址', 20 `buyer_openid` varchar(64) NOT NULL COMMENT '买家微信openId', 21 `buyer_amount` decimal(8,2) NOT NULL COMMENT '订单总额', 22 `buyer_status` tinyint(3) NOT NULL DEFAULT '0' COMMENT '订单状态,默认0新下单', 23 `pay_status` tinyint(3) NOT NULL DEFAULT '0' COMMENT '支付状态,默认0未支付', 24 `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', 25 `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', 26 PRIMARY KEY (`order_id`), 27 KEY `idx_buyer_openid` (`buyer_openid`) 28) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='订单表'; 29 30CREATE TABLE `product_category` ( 31 `category_id` int(11) NOT NULL AUTO_INCREMENT, 32 `category_name` varchar(64) NOT NULL COMMENT '类别名称', 33 `category_type` int(11) NOT NULL COMMENT '类名编号', 34 `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', 35 `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', 36 PRIMARY KEY (`category_id`), 37 UNIQUE KEY `uqe_category_type` (`category_type`) 38) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='类别表'; 39 40CREATE TABLE `product_info` ( 41 `product_id` varchar(32) NOT NULL, 42 `product_name` varchar(64) NOT NULL COMMENT '产品名称', 43 `product_price` decimal(8,2) NOT NULL COMMENT '价格', 44 `product_stock` int(11) NOT NULL COMMENT '库存', 45 `product_description` varchar(64) DEFAULT NULL COMMENT '描述', 46 `product_icon` varchar(512) DEFAULT NULL COMMENT '图标', 47 `product_type` int(11) NOT NULL COMMENT '产品类型', 48 `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', 49 `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', 50 PRIMARY KEY (`product_id`) 51) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='产品表';