前言
reggie项目基于SpringBoot分模块整合SSM框架,至此1个可以开发大型JavaWeb应用的开发框架已经整合完成;
一、瑞吉点餐项目介绍
1.项目介绍
系统管理后台:主要提供给餐饮企业内部员工使用,可以对餐厅的分类、菜品、套餐、订单、员工等进行管理维护。
移动端应用: 主要提供给客户使用,可以在线浏览菜品、添加购物车、下单等。
关于本项目的技术选型, 我们将会从 用户层、网关层、应用层、数据层进行介绍,对服务端开发工程师来说,主要关注应用层及数据层技术。
3.项目演示
二、项目搭建
本项目基于Maven进行分模块开发
1.数据导入
/* SQLyog v10.2 MySQL - 5.7.27 : Database - reggie ********************************************************************* */ /*!40101 SET NAMES utf8 */; /*!40101 SET SQL_MODE=''*/; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; CREATE DATABASE /*!32312 IF NOT EXISTS*/`reggie` /*!40100 DEFAULT CHARACTER SET utf8 */; USE `reggie`; /*Table structure for table `address_book` */ DROP TABLE IF EXISTS `address_book`; CREATE TABLE `address_book` ( `id` bigint(20) NOT NULL COMMENT '主键', `user_id` bigint(20) NOT NULL COMMENT '用户id', `consignee` varchar(50) COLLATE utf8_bin NOT NULL COMMENT '收货人', `sex` tinyint(4) NOT NULL COMMENT '性别 0 女 1 男', `phone` varchar(11) COLLATE utf8_bin NOT NULL COMMENT '手机号', `province_code` varchar(12) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '省级区划编号', `province_name` varchar(32) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '省级名称', `city_code` varchar(12) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '市级区划编号', `city_name` varchar(32) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '市级名称', `district_code` varchar(12) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '区级区划编号', `district_name` varchar(32) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '区级名称', `detail` varchar(200) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '详细地址', `label` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '标签', `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT '默认 0 否 1是', `create_time` datetime NOT NULL COMMENT '创建时间', `update_time` datetime NOT NULL COMMENT '更新时间', `create_user` bigint(20) NOT NULL COMMENT '创建人', `update_user` bigint(20) NOT NULL COMMENT '修改人', `is_deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='地址管理'; /*Data for the table `address_book` */ insert into `address_book`(`id`,`user_id`,`consignee`,`sex`,`phone`,`province_code`,`province_name`,`city_code`,`city_name`,`district_code`,`district_name`,`detail`,`label`,`is_default`,`create_time`,`update_time`,`create_user`,`update_user`,`is_deleted`) values (1417414526093082626,1417012167126876162,'小明',1,'13812345678',NULL,NULL,NULL,NULL,NULL,NULL,'昌平区金燕龙办公楼','公司',1,'2021-07-20 17:22:12','2021-07-20 17:26:33',1417012167126876162,1417012167126876162,0),(1417414926166769666,1417012167126876162,'小李',1,'13512345678',NULL,NULL,NULL,NULL,NULL,NULL,'测试','家',0,'2021-07-20 17:23:47','2021-07-20 17:23:47',1417012167126876162,1417012167126876162,0),(1458313328639082498,1458312187708702721,'郭新明',1,'13700137001',NULL,NULL,NULL,NULL,NULL,NULL,'11','公司',1,'2021-11-10 13:59:26','2021-11-10 14:03:51',1458312187708702721,1458312187708702721,0); /*Table structure for table `category` */ DROP TABLE IF EXISTS `category`; CREATE TABLE `category` ( `id` bigint(20) NOT NULL COMMENT '主键', `type` int(11) DEFAULT NULL COMMENT '类型 1 菜品分类 2 套餐分类', `name` varchar(64) COLLATE utf8_bin NOT NULL COMMENT '分类名称', `sort` int(11) NOT NULL DEFAULT '0' COMMENT '顺序', `create_time` datetime NOT NULL COMMENT '创建时间', `update_time` datetime NOT NULL COMMENT '更新时间', `create_user` bigint(20) NOT NULL COMMENT '创建人', `update_user` bigint(20) NOT NULL COMMENT '修改人', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `idx_category_name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='菜品及套餐分类'; /*Data for the table `category` */ insert into `category`(`id`,`type`,`name`,`sort`,`create_time`,`update_time`,`create_user`,`update_user`) values (1397844263642378242,1,'湘菜',1,'2021-05-27 09:16:58','2021-07-15 20:25:23',1,1),(1397844303408574465,1,'川菜',2,'2021-05-27 09:17:07','2021-06-02 14:27:22',1,1),(1397844391040167938,1,'粤菜',3,'2021-05-27 09:17:28','2021-07-09 14:37:13',1,1),(1413341197421846529,1,'饮品',11,'2021-07-09 11:36:15','2021-07-09 14:39:15',1,1),(1413342269393674242,2,'商务套餐',5,'2021-07-09 11:40:30','2021-07-09 14:43:45',1,1),(1413384954989060097,1,'主食',12,'2021-07-09 14:30:07','2021-07-09 14:39:19',1,1),(1413386191767674881,2,'儿童套餐',6,'2021-07-09 14:35:02','2021-07-09 14:39:05',1,1); /*Table structure for table `dish` */ DROP TABLE IF EXISTS `dish`; CREATE TABLE `dish` ( `id` bigint(20) NOT NULL COMMENT '主键', `name` varchar(64) COLLATE utf8_bin NOT NULL COMMENT '菜品名称', `category_id` bigint(20) NOT NULL COMMENT '菜品分类id', `price` decimal(10,2) DEFAULT NULL COMMENT '菜品价格', `code` varchar(64) COLLATE utf8_bin NOT NULL COMMENT '商品码', `image` varchar(200) COLLATE utf8_bin NOT NULL COMMENT '图片', `description` varchar(400) COLLATE utf8_bin DEFAULT NULL COMMENT '描述信息', `status` int(11) NOT NULL DEFAULT '1' COMMENT '0 停售 1 起售', `sort` int(11) NOT NULL DEFAULT '0' COMMENT '顺序', `create_time` datetime NOT NULL COMMENT '创建时间', `update_time` datetime NOT NULL COMMENT '更新时间', `create_user` bigint(20) NOT NULL COMMENT '创建人', `update_user` bigint(20) NOT NULL COMMENT '修改人', `is_deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `idx_dish_name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='菜品管理'; /*Data for the table `dish` */ insert into `dish`(`id`,`name`,`category_id`,`price`,`code`,`image`,`description`,`status`,`sort`,`create_time`,`update_time`,`create_user`,`update_user`,`is_deleted`) values (1397849739276890114,'辣子鸡',1397844263642378242,'7800.00','222222222','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/f966a38e-0780-40be-bb52-5699d13cb3d9.jpg','来自鲜嫩美味的小鸡,值得一尝',1,0,'2021-05-27 09:38:43','2021-05-27 09:38:43',1,1,0),(1397850140982161409,'毛氏红烧肉',1397844263642378242,'6800.00','123412341234','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/0a3b3288-3446-4420-bbff-f263d0c02d8e.jpg','毛氏红烧肉毛氏红烧肉,确定不来一份?',1,0,'2021-05-27 09:40:19','2021-05-27 09:40:19',1,1,0),(1397850392090947585,'组庵鱼翅',1397844263642378242,'4800.00','123412341234','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/740c79ce-af29-41b8-b78d-5f49c96e38c4.jpg','组庵鱼翅,看图足以表明好吃程度',1,0,'2021-05-27 09:41:19','2021-05-27 09:41:19',1,1,0),(1397850851245600769,'霸王别姬',1397844263642378242,'12800.00','123412341234','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/057dd338-e487-4bbc-a74c-0384c44a9ca3.jpg','还有什么比霸王别姬更美味的呢?',1,0,'2021-05-27 09:43:08','2021-05-27 09:43:08',1,1,0),(1397851099502260226,'全家福',1397844263642378242,'11800.00','23412341234','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/a53a4e6a-3b83-4044-87f9-9d49b30a8fdc.jpg','别光吃肉啦,来份全家福吧,让你长寿又美味',1,0,'2021-05-27 09:44:08','2021-05-27 09:44:08',1,1,0),(1397851370462687234,'邵阳猪血丸子',1397844263642378242,'13800.00','1246812345678','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/2a50628e-7758-4c51-9fbb-d37c61cdacad.jpg','看,美味不?来嘛来嘛,这才是最爱吖',1,0,'2021-05-27 09:45:12','2021-05-27 09:45:12',1,1,0),(1397851668262465537,'口味蛇',1397844263642378242,'16800.00','1234567812345678','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/0f4bd884-dc9c-4cf9-b59e-7d5958fec3dd.jpg','爬行界的扛把子,东兴-口味蛇,让你欲罢不能',1,0,'2021-05-27 09:46:23','2021-05-27 09:46:23',1,1,0),(1397852391150759938,'辣子鸡丁',1397844303408574465,'8800.00','2346812468','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/ef2b73f2-75d1-4d3a-beea-22da0e1421bd.jpg','辣子鸡丁,辣子鸡丁,永远的魂',1,0,'2021-05-27 09:49:16','2021-05-27 09:49:16',1,1,0),(1397853183287013378,'麻辣兔头',1397844303408574465,'19800.00','123456787654321','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/2a2e9d66-b41d-4645-87bd-95f2cfeed218.jpg','麻辣兔头的详细制作,麻辣鲜香,色泽红润,回味悠长',1,0,'2021-05-27 09:52:24','2021-05-27 09:52:24',1,1,0),(1397853709101740034,'蒜泥白肉',1397844303408574465,'9800.00','1234321234321','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/d2f61d70-ac85-4529-9b74-6d9a2255c6d7.jpg','多么的有食欲啊',1,0,'2021-05-27 09:54:30','2021-05-27 09:54:30',1,1,0),(1397853890262118402,'鱼香肉丝',1397844303408574465,'3800.00','1234212321234','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/8dcfda14-5712-4d28-82f7-ae905b3c2308.jpg','鱼香肉丝简直就是我们童年回忆的一道经典菜,上学的时候点个鱼香肉丝盖饭坐在宿舍床上看着肥皂剧,绝了!现在完美复刻一下上学的时候感觉',1,0,'2021-05-27 09:55:13','2021-05-27 09:55:13',1,1,0),(1397854652581064706,'麻辣水煮鱼',1397844303408574465,'14800.00','2345312·345321','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/1fdbfbf3-1d86-4b29-a3fc-46345852f2f8.jpg','鱼片是买的切好的鱼片,放几个虾,增加味道',1,0,'2021-05-27 09:58:15','2021-05-27 09:58:15',1,1,0),(1397854865672679425,'鱼香炒鸡蛋',1397844303408574465,'2000.00','23456431·23456','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/0f252364-a561-4e8d-8065-9a6797a6b1d3.jpg','鱼香菜也是川味的特色。里面没有鱼却鱼香味',1,0,'2021-05-27 09:59:06','2021-05-27 09:59:06',1,1,0),(1397860242057375745,'脆皮烧鹅',1397844391040167938,'12800.00','123456786543213456','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/e476f679-5c15-436b-87fa-8c4e9644bf33.jpeg','“广东烤鸭美而香,却胜烧鹅说古冈(今新会),燕瘦环肥各佳妙,君休偏重便宜坊”,可见烧鹅与烧鸭在粤菜之中已早负盛名。作为广州最普遍和最受欢迎的烧烤肉食,以它的“色泽金红,皮脆肉嫩,味香可口”的特色,在省城各大街小巷的烧卤店随处可见。',1,0,'2021-05-27 10:20:27','2021-05-27 10:20:27',1,1,0),(1397860578738352129,'白切鸡',1397844391040167938,'6600.00','12345678654','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/9ec6fc2d-50d2-422e-b954-de87dcd04198.jpeg','白切鸡是一道色香味俱全的特色传统名肴,又叫白斩鸡,是粤菜系鸡肴中的一种,始于清代的民间。白切鸡通常选用细骨农家鸡与沙姜、蒜茸等食材,慢火煮浸白切鸡皮爽肉滑,清淡鲜美。著名的泮溪酒家白切鸡,曾获商业部优质产品金鼎奖。湛江白切鸡更是驰名粤港澳。粤菜厨坛中,鸡的菜式有200余款之多,而最为人常食不厌的正是白切鸡,深受食家青睐。',1,0,'2021-05-27 10:21:48','2021-05-27 10:21:48',1,1,0),(1397860792492666881,'烤乳猪',1397844391040167938,'38800.00','213456432123456','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/2e96a7e3-affb-438e-b7c3-e1430df425c9.jpeg','广式烧乳猪主料是小乳猪,辅料是蒜,调料是五香粉、芝麻酱、八角粉等,本菜品主要通过将食材放入炭火中烧烤而成。烤乳猪是广州最著名的特色菜,并且是“满汉全席”中的主打菜肴之一。烤乳猪也是许多年来广东人祭祖的祭品之一,是家家都少不了的应节之物,用乳猪祭完先人后,亲戚们再聚餐食用。',1,0,'2021-05-27 10:22:39','2021-05-27 10:22:39',1,1,0),(1397860963880316929,'脆皮乳鸽',1397844391040167938,'10800.00','1234563212345','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/3fabb83a-1c09-4fd9-892b-4ef7457daafa.jpeg','“脆皮乳鸽”是广东菜中的一道传统名菜,属于粤菜系,具有皮脆肉嫩、色泽红亮、鲜香味美的特点,常吃可使身体强健,清肺顺气。随着菜品制作工艺的不断发展,逐渐形成了熟炸法、生炸法和烤制法三种制作方法。无论那种制作方法,都是在鸽子经过一系列的加工,挂脆皮水后再加工而成,正宗的“脆皮乳鸽皮脆肉嫩、色泽红亮、鲜香味美、香气馥郁。这三种方法的制作过程都不算复杂,但想达到理想的效果并不容易。',1,0,'2021-05-27 10:23:19','2021-05-27 10:23:19',1,1,0),(1397861683434139649,'清蒸河鲜海鲜',1397844391040167938,'38800.00','1234567876543213456','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/1405081e-f545-42e1-86a2-f7559ae2e276.jpeg','新鲜的海鲜,清蒸是最好的处理方式。鲜,体会为什么叫海鲜。清蒸是广州最经典的烹饪手法,过去岭南地区由于峻山大岭阻隔,交通不便,经济发展起步慢,自家打的鱼放在锅里煮了就吃,没有太多的讲究,但却发现这清淡的煮法能使鱼的鲜甜跃然舌尖。',1,0,'2021-05-27 10:26:11','2021-05-27 10:26:11',1,1,0),(1397862198033297410,'老火靓汤',1397844391040167938,'49800.00','123456786532455','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/583df4b7-a159-4cfc-9543-4f666120b25f.jpeg','老火靓汤又称广府汤,是广府人传承数千年的食补养生秘方,慢火煲煮的中华老火靓汤,火候足,时间长,既取药补之效,又取入口之甘甜。 广府老火汤种类繁多,可以用各种汤料和烹调方法,烹制出各种不同口味、不同功效的汤来。',1,0,'2021-05-27 10:28:14','2021-05-27 10:28:14',1,1,0),(1397862477831122945,'上汤焗龙虾',1397844391040167938,'108800.00','1234567865432','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/5b8d2da3-3744-4bb3-acdc-329056b8259d.jpeg','上汤焗龙虾是一道色香味俱全的传统名菜,属于粤菜系。此菜以龙虾为主料,配以高汤制成的一道海鲜美食。本品肉质洁白细嫩,味道鲜美,蛋白质含量高,脂肪含量低,营养丰富。是色香味俱全的传统名菜。',1,0,'2021-05-27 10:29:20','2021-05-27 10:29:20',1,1,0),(1413342036832100354,'北冰洋',1413341197421846529,'500.00','','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/c99e0aab-3cb7-4eaa-80fd-f47d4ffea694.png','',1,0,'2021-07-09 11:39:35','2021-07-09 15:12:18',1,1,0),(1413384757047271425,'王老吉',1413341197421846529,'500.00','','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/00874a5e-0df2-446b-8f69-a30eb7d88ee8.png','',1,0,'2021-07-09 14:29:20','2021-07-12 09:09:16',1,1,0),(1413385247889891330,'米饭',1413384954989060097,'200.00','','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/ee04a05a-1230-46b6-8ad5-1a95b140fff3.png','',1,0,'2021-07-09 14:31:17','2021-07-11 16:35:26',1,1,0); /*Table structure for table `dish_flavor` */ DROP TABLE IF EXISTS `dish_flavor`; CREATE TABLE `dish_flavor` ( `id` bigint(20) NOT NULL COMMENT '主键', `dish_id` bigint(20) NOT NULL COMMENT '菜品', `name` varchar(64) COLLATE utf8_bin NOT NULL COMMENT '口味名称', `value` varchar(500) COLLATE utf8_bin DEFAULT NULL COMMENT '口味数据list', `create_time` datetime NOT NULL COMMENT '创建时间', `update_time` datetime NOT NULL COMMENT '更新时间', `create_user` bigint(20) NOT NULL COMMENT '创建人', `update_user` bigint(20) NOT NULL COMMENT '修改人', `is_deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='菜品口味关系表'; /*Data for the table `dish_flavor` */ insert into `dish_flavor`(`id`,`dish_id`,`name`,`value`,`create_time`,`update_time`,`create_user`,`update_user`,`is_deleted`) values (1397849417888346113,1397849417854791681,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:37:27','2021-05-27 09:37:27',1,1,0),(1397849739297861633,1397849739276890114,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 09:38:43','2021-05-27 09:38:43',1,1,0),(1397849739323027458,1397849739276890114,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:38:43','2021-05-27 09:38:43',1,1,0),(1397849936421761025,1397849936404983809,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 09:39:30','2021-05-27 09:39:30',1,1,0),(1397849936438538241,1397849936404983809,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:39:30','2021-05-27 09:39:30',1,1,0),(1397850141015715841,1397850140982161409,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 09:40:19','2021-05-27 09:40:19',1,1,0),(1397850141040881665,1397850140982161409,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:40:19','2021-05-27 09:40:19',1,1,0),(1397850392120307713,1397850392090947585,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:41:19','2021-05-27 09:41:19',1,1,0),(1397850392137084929,1397850392090947585,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:41:19','2021-05-27 09:41:19',1,1,0),(1397850630734262274,1397850630700707841,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 09:42:16','2021-05-27 09:42:16',1,1,0),(1397850630755233794,1397850630700707841,'辣度','[\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:42:16','2021-05-27 09:42:16',1,1,0),(1397850851274960898,1397850851245600769,'忌口','[\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 09:43:08','2021-05-27 09:43:08',1,1,0),(1397850851283349505,1397850851245600769,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:43:08','2021-05-27 09:43:08',1,1,0),(1397851099523231745,1397851099502260226,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 09:44:08','2021-05-27 09:44:08',1,1,0),(1397851099527426050,1397851099502260226,'辣度','[\"不辣\",\"微辣\",\"中辣\"]','2021-05-27 09:44:08','2021-05-27 09:44:08',1,1,0),(1397851370483658754,1397851370462687234,'温度','[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]','2021-05-27 09:45:12','2021-05-27 09:45:12',1,1,0),(1397851370483658755,1397851370462687234,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 09:45:12','2021-05-27 09:45:12',1,1,0),(1397851370483658756,1397851370462687234,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:45:12','2021-05-27 09:45:12',1,1,0),(1397851668283437058,1397851668262465537,'温度','[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]','2021-05-27 09:46:23','2021-05-27 09:46:23',1,1,0),(1397852391180120065,1397852391150759938,'忌口','[\"不要葱\",\"不要香菜\",\"不要辣\"]','2021-05-27 09:49:16','2021-05-27 09:49:16',1,1,0),(1397852391196897281,1397852391150759938,'辣度','[\"不辣\",\"微辣\",\"重辣\"]','2021-05-27 09:49:16','2021-05-27 09:49:16',1,1,0),(1397853183307984898,1397853183287013378,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:52:24','2021-05-27 09:52:24',1,1,0),(1397853423486414850,1397853423461249026,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:53:22','2021-05-27 09:53:22',1,1,0),(1397853709126905857,1397853709101740034,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 09:54:30','2021-05-27 09:54:30',1,1,0),(1397853890283089922,1397853890262118402,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:55:13','2021-05-27 09:55:13',1,1,0),(1397854133632413697,1397854133603053569,'温度','[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]','2021-05-27 09:56:11','2021-05-27 09:56:11',1,1,0),(1397854652623007745,1397854652581064706,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 09:58:15','2021-05-27 09:58:15',1,1,0),(1397854652635590658,1397854652581064706,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:58:15','2021-05-27 09:58:15',1,1,0),(1397854865735593986,1397854865672679425,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 09:59:06','2021-05-27 09:59:06',1,1,0),(1397855742303186946,1397855742273826817,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 10:02:35','2021-05-27 10:02:35',1,1,0),(1397855906497605633,1397855906468245506,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 10:03:14','2021-05-27 10:03:14',1,1,0),(1397856190573621250,1397856190540066818,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 10:04:21','2021-05-27 10:04:21',1,1,0),(1397859056709316609,1397859056684150785,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 10:15:45','2021-05-27 10:15:45',1,1,0),(1397859277837217794,1397859277812051969,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 10:16:37','2021-05-27 10:16:37',1,1,0),(1397859487502086146,1397859487476920321,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 10:17:27','2021-05-27 10:17:27',1,1,0),(1397859757061615618,1397859757036449794,'甜味','[\"无糖\",\"少糖\",\"半躺\",\"多糖\",\"全糖\"]','2021-05-27 10:18:32','2021-05-27 10:18:32',1,1,0),(1397860242086735874,1397860242057375745,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 10:20:27','2021-05-27 10:20:27',1,1,0),(1397860963918065665,1397860963880316929,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 10:23:19','2021-05-27 10:23:19',1,1,0),(1397861135754506242,1397861135733534722,'甜味','[\"无糖\",\"少糖\",\"半躺\",\"多糖\",\"全糖\"]','2021-05-27 10:24:00','2021-05-27 10:24:00',1,1,0),(1397861370035744769,1397861370010578945,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-27 10:24:56','2021-05-27 10:24:56',1,1,0),(1397861683459305474,1397861683434139649,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 10:26:11','2021-05-27 10:26:11',1,1,0),(1397861898467717121,1397861898438356993,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 10:27:02','2021-05-27 10:27:02',1,1,0),(1397862198054268929,1397862198033297410,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-27 10:28:14','2021-05-27 10:28:14',1,1,0),(1397862477835317250,1397862477831122945,'辣度','[\"不辣\",\"微辣\",\"中辣\"]','2021-05-27 10:29:20','2021-05-27 10:29:20',1,1,0),(1398089545865015297,1398089545676271617,'温度','[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]','2021-05-28 01:31:38','2021-05-28 01:31:38',1,1,0),(1398089782323097601,1398089782285348866,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-28 01:32:34','2021-05-28 01:32:34',1,1,0),(1398090003262255106,1398090003228700673,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-28 01:33:27','2021-05-28 01:33:27',1,1,0),(1398090264554811394,1398090264517062657,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-28 01:34:29','2021-05-28 01:34:29',1,1,0),(1398090455399837698,1398090455324340225,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-28 01:35:14','2021-05-28 01:35:14',1,1,0),(1398090685449023490,1398090685419663362,'温度','[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]','2021-05-28 01:36:09','2021-05-28 01:36:09',1,1,0),(1398090825358422017,1398090825329061889,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-28 01:36:43','2021-05-28 01:36:43',1,1,0),(1398091007051476993,1398091007017922561,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-28 01:37:26','2021-05-28 01:37:26',1,1,0),(1398091296164851713,1398091296131297281,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-28 01:38:35','2021-05-28 01:38:35',1,1,0),(1398091546531246081,1398091546480914433,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]','2021-05-28 01:39:35','2021-05-28 01:39:35',1,1,0),(1398091729809747969,1398091729788776450,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-28 01:40:18','2021-05-28 01:40:18',1,1,0),(1398091889499484161,1398091889449152513,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-28 01:40:56','2021-05-28 01:40:56',1,1,0),(1398092095179763713,1398092095142014978,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-28 01:41:45','2021-05-28 01:41:45',1,1,0),(1398092283877306370,1398092283847946241,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-28 01:42:30','2021-05-28 01:42:30',1,1,0),(1398094018939236354,1398094018893099009,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-28 01:49:24','2021-05-28 01:49:24',1,1,0),(1398094391494094850,1398094391456346113,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-05-28 01:50:53','2021-05-28 01:50:53',1,1,0),(1399574026165727233,1399305325713600514,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]','2021-06-01 03:50:25','2021-06-01 03:50:25',1399309715396669441,1399309715396669441,0),(1413389540592263169,1413384757047271425,'温度','[\"常温\",\"冷藏\"]','2021-07-12 09:09:16','2021-07-12 09:09:16',1,1,0),(1413389684020682754,1413342036832100354,'温度','[\"常温\",\"冷藏\"]','2021-07-09 15:12:18','2021-07-09 15:12:18',1,1,0); /*Table structure for table `employee` */ DROP TABLE IF EXISTS `employee`; CREATE TABLE `employee` ( `id` bigint(20) NOT NULL COMMENT '主键', `name` varchar(32) COLLATE utf8_bin NOT NULL COMMENT '姓名', `username` varchar(32) COLLATE utf8_bin NOT NULL COMMENT '用户名', `password` varchar(64) COLLATE utf8_bin NOT NULL COMMENT '密码', `phone` varchar(11) COLLATE utf8_bin NOT NULL COMMENT '手机号', `sex` varchar(2) COLLATE utf8_bin NOT NULL COMMENT '性别', `id_number` varchar(18) COLLATE utf8_bin NOT NULL COMMENT '身份证号', `status` int(11) NOT NULL DEFAULT '1' COMMENT '状态 0:禁用,1:正常', `create_time` datetime NOT NULL COMMENT '创建时间', `update_time` datetime NOT NULL COMMENT '更新时间', `create_user` bigint(20) NOT NULL COMMENT '创建人', `update_user` bigint(20) NOT NULL COMMENT '修改人', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `idx_username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='员工信息'; /*Data for the table `employee` */ insert into `employee`(`id`,`name`,`username`,`password`,`phone`,`sex`,`id_number`,`status`,`create_time`,`update_time`,`create_user`,`update_user`) values (1,'管理员','admin','e10adc3949ba59abbe56e057f20f883e','13812312312','1','110101199001010047',1,'2021-05-06 17:20:07','2021-05-10 02:24:09',1,1); /*Table structure for table `order_detail` */ DROP TABLE IF EXISTS `order_detail`; CREATE TABLE `order_detail` ( `id` bigint(20) NOT NULL COMMENT '主键', `name` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '名字', `image` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '图片', `order_id` bigint(20) NOT NULL COMMENT '订单id', `dish_id` bigint(20) DEFAULT NULL COMMENT '菜品id', `setmeal_id` bigint(20) DEFAULT NULL COMMENT '套餐id', `dish_flavor` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '口味', `number` int(11) NOT NULL DEFAULT '1' COMMENT '数量', `amount` decimal(10,2) NOT NULL COMMENT '金额', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='订单明细表'; /*Data for the table `order_detail` */ insert into `order_detail`(`id`,`name`,`image`,`order_id`,`dish_id`,`setmeal_id`,`dish_flavor`,`number`,`amount`) values (1458314534728081410,'蒜泥白肉','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/d2f61d70-ac85-4529-9b74-6d9a2255c6d7.jpg',1458314534728081409,1397853709101740034,NULL,'不要辣',1,'98.00'); /*Table structure for table `orders` */ DROP TABLE IF EXISTS `orders`; CREATE TABLE `orders` ( `id` bigint(20) NOT NULL COMMENT '主键', `number` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '订单号', `status` int(11) NOT NULL DEFAULT '1' COMMENT '订单状态 1待付款,2待派送,3已派送,4已完成,5已取消', `user_id` bigint(20) NOT NULL COMMENT '下单用户', `address_id` bigint(20) NOT NULL COMMENT '地址id', `order_time` datetime NOT NULL COMMENT '下单时间', `checkout_time` datetime NOT NULL COMMENT '结账时间', `pay_method` int(11) NOT NULL DEFAULT '1' COMMENT '支付方式 1微信,2支付宝', `amount` decimal(10,2) NOT NULL COMMENT '实收金额', `remark` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '备注', `phone` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '手机', `address` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '收货地址', `user_name` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '用户名', `consignee` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '收货人', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='订单表'; /*Data for the table `orders` */ insert into `orders`(`id`,`number`,`status`,`user_id`,`address_id`,`order_time`,`checkout_time`,`pay_method`,`amount`,`remark`,`phone`,`address`,`user_name`,`consignee`) values (1458314534728081409,'1458314534728081409',1,1458312187708702721,1458313328639082498,'2021-11-10 14:04:13','2021-11-10 14:04:13',1,'98.00','多要一只筷子','13700137001','11',NULL,'郭新明'); /*Table structure for table `setmeal` */ DROP TABLE IF EXISTS `setmeal`; CREATE TABLE `setmeal` ( `id` bigint(20) NOT NULL COMMENT '主键', `category_id` bigint(20) NOT NULL COMMENT '菜品分类id', `name` varchar(64) COLLATE utf8_bin NOT NULL COMMENT '套餐名称', `price` decimal(10,2) NOT NULL COMMENT '套餐价格', `status` int(11) DEFAULT NULL COMMENT '状态 0:停用 1:启用', `code` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT '编码', `description` varchar(512) COLLATE utf8_bin DEFAULT NULL COMMENT '描述信息', `image` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '图片', `create_time` datetime NOT NULL COMMENT '创建时间', `update_time` datetime NOT NULL COMMENT '更新时间', `create_user` bigint(20) NOT NULL COMMENT '创建人', `update_user` bigint(20) NOT NULL COMMENT '修改人', `is_deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `idx_setmeal_name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='套餐'; /*Data for the table `setmeal` */ insert into `setmeal`(`id`,`category_id`,`name`,`price`,`status`,`code`,`description`,`image`,`create_time`,`update_time`,`create_user`,`update_user`,`is_deleted`) values (1415580119015145474,1413386191767674881,'儿童套餐A计划','4000.00',1,'','','https://tanhua-gxm.oss-cn-beijing.aliyuncs.com/reggie/f966a38e-0780-40be-bb52-5699d13cb3d9.jpg','2021-07-15 15:52:55','2021-07-15 15:52:55',1415576781934608386,1415576781934608386,0); /*Table structure for table `setmeal_dish` */ DROP TABLE IF EXISTS `setmeal_dish`; CREATE TABLE `setmeal_dish` ( `id` bigint(20) NOT NULL COMMENT '主键', `setmeal_id` varchar(32) COLLATE utf8_bin NOT NULL COMMENT '套餐id ', `dish_id` varchar(32) COLLATE utf8_bin NOT NULL COMMENT '菜品id', `name` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT '菜品名称 (冗余字段)', `price` decimal(10,2) DEFAULT NULL COMMENT '菜品原价(冗余字段)', `copies` int(11) NOT NULL COMMENT '份数', `sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序', `create_time` datetime NOT NULL COMMENT '创建时间', `update_time` datetime NOT NULL COMMENT '更新时间', `create_user` bigint(20) NOT NULL COMMENT '创建人', `update_user` bigint(20) NOT NULL COMMENT '修改人', `is_deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='套餐菜品关系'; /*Data for the table `setmeal_dish` */ insert into `setmeal_dish`(`id`,`setmeal_id`,`dish_id`,`name`,`price`,`copies`,`sort`,`create_time`,`update_time`,`create_user`,`update_user`,`is_deleted`) values (1415580119052894209,'1415580119015145474','1397862198033297410','老火靓汤','49800.00',1,0,'2021-07-15 15:52:55','2021-07-15 15:52:55',1415576781934608386,1415576781934608386,0),(1415580119061282817,'1415580119015145474','1413342036832100354','北冰洋','500.00',1,0,'2021-07-15 15:52:55','2021-07-15 15:52:55',1415576781934608386,1415576781934608386,0),(1415580119069671426,'1415580119015145474','1413385247889891330','米饭','200.00',1,0,'2021-07-15 15:52:55','2021-07-15 15:52:55',1415576781934608386,1415576781934608386,0); /*Table structure for table `shopping_cart` */ DROP TABLE IF EXISTS `shopping_cart`; CREATE TABLE `shopping_cart` ( `id` bigint(20) NOT NULL COMMENT '主键', `name` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '名称', `image` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '图片', `user_id` bigint(20) NOT NULL COMMENT '主键', `dish_id` bigint(20) DEFAULT NULL COMMENT '菜品id', `setmeal_id` bigint(20) DEFAULT NULL COMMENT '套餐id', `dish_flavor` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '口味', `number` int(11) NOT NULL DEFAULT '1' COMMENT '数量', `amount` decimal(10,2) NOT NULL COMMENT '金额', `create_time` datetime DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='购物车'; /*Data for the table `shopping_cart` */ /*Table structure for table `user` */ DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` bigint(20) NOT NULL COMMENT '主键', `name` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '姓名', `phone` varchar(100) COLLATE utf8_bin NOT NULL COMMENT '手机号', `sex` varchar(2) COLLATE utf8_bin DEFAULT NULL COMMENT '性别', `id_number` varchar(18) COLLATE utf8_bin DEFAULT NULL COMMENT '身份证号', `avatar` varchar(500) COLLATE utf8_bin DEFAULT NULL COMMENT '头像', `status` int(11) DEFAULT '0' COMMENT '状态 0:禁用,1:正常', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='用户信息'; /*Data for the table `user` */ insert into `user`(`id`,`name`,`phone`,`sex`,`id_number`,`avatar`,`status`) values (1458310743471493121,NULL,'13700137000',NULL,NULL,NULL,1),(1458311824620388353,NULL,'13700137002',NULL,NULL,NULL,1),(1458312187708702721,NULL,'13700137001',NULL,NULL,NULL,1); /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
数据表表
说明 | |
---|---|
employee | 员工表 |
category | 菜品和套餐分类表 |
dish | 菜品表 |
setmeal | 套餐表 |
setmeal_dish | 套餐菜品关系表 |
dish_flavor | 菜品口味关系表 |
user | 用户表(C端) |
address_book | 地址簿表 |
shopping_cart | 购物车表 |
orders | 订单表 |
order_detail |
2.模块设计
使用maven分模块开发
3.环境搭建
<?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.itheima</groupId> <artifactId>reggie-parent</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <modules> <module>reggie-domain</module> <module>reggie-common</module> <module>reggie-mapper</module> <module>reggie-service</module> <module>reggie-web-manage</module> </modules> <properties> <java.version>1.8</java.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.5</version> <relativePath/> </parent> <dependencies> <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-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.7.1</version> <scope>compile</scope> </dependency> <!--数据层--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.23</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency> <!-- <dependency>--> <!-- <groupId>com.baomidou</groupId>--> <!-- <artifactId>mybatis-plus-boot-starter</artifactId>--> <!-- <version>3.4.2</version>--> <!-- </dependency>--> <!--阿里云--> <dependency> <groupId>com.aliyun.oss</groupId> <artifactId>aliyun-sdk-oss</artifactId> <version>3.10.2</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.0.6</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-dysmsapi</artifactId> <version>1.1.0</version> </dependency> <!--工具类--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.76</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.20</version> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.4.3</version> </dependency> <!--热部署--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
<?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"> <parent> <artifactId>reggie-parent</artifactId> <groupId>com.itheima</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>reggie-common</artifactId> <dependencies> <dependency> <groupId>com.itheima</groupId> <artifactId>reggie-domain</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project>
<?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"> <parent> <artifactId>reggie-parent</artifactId> <groupId>com.itheima</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>reggie-mapper</artifactId> <dependencies> <dependency> <groupId>com.itheima</groupId> <artifactId>reggie-common</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project>
<?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"> <parent> <artifactId>reggie-parent</artifactId> <groupId>com.itheima</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>reggie-service</artifactId> <dependencies> <dependency> <groupId>com.itheima</groupId> <artifactId>reggie-mapper</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project>
创建reggie-web-manage
模块
用于存放管理后台的表示层代码,本模块需要依赖reggie-service
模块
<?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"> <parent> <artifactId>reggie-parent</artifactId> <groupId>com.itheima</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>reggie-web-manage</artifactId> <dependencies> <dependency> <groupId>com.itheima</groupId> <artifactId>reggie-service</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
添加配置文件
server: port: 8080 spring: application: name: reggie-web-manage # 应用名称 datasource: # 数据源配置 druid: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/reggie?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: root mybatis: configuration: map-underscore-to-camel-case: true # 驼峰命名法映射 address_book ---> AddressBook log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 日志输出 mapper-locations: classpath:/mappers/**.xml # 指定xml位置
创建启动类
package com.itheima.reggie; import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication//主类 @MapperScan("com.itheima.reggie.mapper")//指定mybatis类所在的包 @EnableTransactionManagement //开启对事物管理的支持 @Slf4j public class WebManageApplication { public static void main(String[] args) { SpringApplication.run(WebManageApplication.class, args); log.info("项目启动成功"); } }
静态资源映射
在SpringMVC中叫释放静态资源,在SpringBoot中是添加静态资源映射;
资料中已经提供好了本项目所需要的静态资源,只需要将其引入到项目的resources即可
而本项目中静态资源存放在backend目录中, 那么这个时候要想访问到静态资源,就需要设置静态资源映射。
创建一个com.itheima.reggie.config.ReggieWebMvcConfig
package com.itheima.reggie.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; //web相关配置 @Configuration public class ReggieWebMvcConfig implements WebMvcConfigurer { //设置静态资源映射 public void addResourceHandlers(ResourceHandlerRegistry registry) { //当访问请求是/backend/**时,去classpath:/backend/寻找对应资源 registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/"); } }
三、员工登录
后台用户(员工)的登录
1.用户密码加密
hutool工具包不仅可以生成验证码,还可以使用hutool工具包(cn.hutool.crypto.SecureUtil)进行md5加密;
2.md5加密字符串对比
使用org.apache.commons.lang3.StringUtils可以对比2个md5加密之后的字符串,没有空指针报错风险;
//hutool工具包SecureUtil,对字符串进行加密,没有空指针风险 String passwordWithMd5 = SecureUtil.md5(password); //lang3工具包StringUtils对比md5加密之后的字符串 if (!StringUtils.equals(passwordWithMd5, employee.getPassword())) { return ResultInfo.error("密码不正确"); }
3.Java中null类型
null可以被强转成任何引用数据类型,不会报错,强转完毕后结果为null;
null不可以被强转转换成基本类型,会报错;
4.Long类型ID精度丢失
Java后端的long类型在JavaScript中表示会丢失精度,我们可以在SpringMVC中定义1个类型转换器;
指定SpringMVC响应给前端的long类型为字符串;
前端传给给SpringMVC后端的字符串类型转换成Long类型;
1.定义转换规则
package com.itheima.reggie.common; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.std.DateSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import java.math.BigInteger; import java.text.SimpleDateFormat; import java.util.Date; import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; /** * 对象映射器:基于jackson将Java对象转为json,或者将json转为Java对象 * 将JSON解析为Java对象的过程称为 [从JSON反序列化Java对象] * 从Java对象生成JSON的过程称为 [序列化Java对象到JSON] */ public class JacksonObjectMapper extends ObjectMapper { public JacksonObjectMapper() { super(); //收到未知属性时不报异常 this.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); //反序列化时,属性不存在的兼容处理 this.getDeserializationConfig().withoutFeatures(FAIL_ON_UNKNOWN_PROPERTIES); //自定义转换规则 SimpleModule simpleModule = new SimpleModule() //将BigInteger转换为String .addSerializer(BigInteger.class, ToStringSerializer.instance) //将Long转换成String .addSerializer(Long.class, ToStringSerializer.instance); this.registerModule(simpleModule); } }
2.SpringMVC配置
package com.itheima.reggie.config; import com.itheima.reggie.common.JacksonObjectMapper; import com.itheima.reggie.interceptor.LoginCheckInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.ArrayList; import java.util.List; //SpringMvc(web层)相关配置 @Configuration public class ReggieWebMvcConfig implements WebMvcConfigurer { //1.释放静态资源 public void addResourceHandlers(ResourceHandlerRegistry registry) { //当访问请求是/backend/**时,去classpath:/backend/寻找对应资源 registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/"); } @Autowired private LoginCheckInterceptor loginCheckInterceptor; //2.配置springBoot的拦截器 @Override public void addInterceptors(InterceptorRegistry registry) { //定义放行路径 ArrayList<String> passUrlList = new ArrayList<>(); passUrlList.add("/backend/**");//管理系统静态资源 passUrlList.add("/error");//错误请求 passUrlList.add("/employee/login");//管理系统登录请求 passUrlList.add("/employee/logout");//管理系统退出请求 registry.addInterceptor(loginCheckInterceptor) .addPathPatterns("/**") .excludePathPatterns(passUrlList); } //扩展mvc框架的消息转换器 public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { //创建消息转换器对象 MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter(); //设置对象转换器,底层使用Jackson将Java对象转为json messageConverter.setObjectMapper(new JacksonObjectMapper()); //将上面的消息转换器对象追加到mvc框架的转换器集合中 converters.add(0, messageConverter); } }
5.雪花算法
使用雪花算法可以根据当前时间的时间戳,生成1个唯一的long类型的数字,并且自增;
hutool工具包可以生成
//雪花算法:(自学一下) Long id = IdUtil.getSnowflake(1, 1).nextId();
6.文件存储方案
1. 直接将图片保存到服务器的硬盘
优点:开发便捷,成本低,数据安全
缺点:扩容困难
2. 自己搭建分布式文件系统进行存储(MiniIO)
优点:容易实现扩容
缺点:开发复杂度稍大
3. 使用第三方的存储服务(阿里云OSS)
优点:开发简单,拥有强大功能,免维护
缺点:数据由第三方托管不安全,付费
API
package com.itheima.reggie.common; import com.aliyun.oss.OSS; import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.model.ObjectMetadata; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.Date; //阿里存储工具类 @Component @ConfigurationProperties(prefix = "reggie.oss")//读取配置信息 @Data public class OssTemplate { private String key; //访问key private String secret;//访问秘钥 private String endpoint;//端点 private String bucket;//桶名 private String url;//访问域名 //文件上传 public String upload(String fileName, InputStream inputStream) { //创建客户端 OSS ossClient = new OSSClientBuilder().build(endpoint, key, secret); //设置文件最终的路径和名称 String objectName = "images/" + new SimpleDateFormat("yyyy/MM/dd").format(new Date()) + "/" + System.currentTimeMillis() + fileName.substring(fileName.lastIndexOf(".")); //meta设置请求头,解决访问图片地址直接下载 ObjectMetadata meta = new ObjectMetadata(); meta.setContentType(getContentType(fileName.substring(fileName.lastIndexOf(".")))); //上传 ossClient.putObject(bucket, objectName, inputStream, meta); //关闭客户端 ossClient.shutdown(); //返回的就是图片访问的全路径 return url + "/" + objectName; } //文件后缀处理 private String getContentType(String FilenameExtension) { if (FilenameExtension.equalsIgnoreCase(".bmp")) { return "image/bmp"; } if (FilenameExtension.equalsIgnoreCase(".gif")) { return "image/gif"; } if (FilenameExtension.equalsIgnoreCase(".jpeg") || FilenameExtension.equalsIgnoreCase(".jpg") || FilenameExtension.equalsIgnoreCase(".png")) { return "image/jpg"; } return "image/jpg"; } }
application.yaml
reggie:
oss:
key: 你的
secret: 你的
endpoint: oss-cn-beijing.aliyuncs.com
bucket: zhanggen-123
url: https://zhanggen-123.oss-cn-beijing.aliyuncs.com
三、用户登录
客户通过手机端进行登录,采用手机号+验证码登录;
1.登录方式
在web应用中有3中常见的登录方式
- 传统的用户名+密码
- 第三方认证登录
- 手机+验证码登录
2.手机+验证码
package com.itheima.reggie.controller; import cn.hutool.core.util.RandomUtil; import com.itheima.reggie.common.ResultInfo; import com.itheima.reggie.common.SmsTemplate; import com.itheima.reggie.domain.User; import com.itheima.reggie.service.UserService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpSession; import java.util.Map; //进点客户端 @RestController @Slf4j public class UserController { @Autowired private HttpSession session; @Autowired private SmsTemplate smsTemplate; @Autowired private UserService userService; //进店用户输入自己的手机号码,点击获取验证码 @PostMapping("/user/sendMsg") public ResultInfo sendMsg(@RequestBody Map<String, String> map) { //1.接收参数 String phone = map.get("phone").trim(); //2.生成验证码 String code = RandomUtil.randomNumbers(6).trim(); log.info("生成的验证码为:{}", code); //3.将当前用户的手机号码做key,验证码做value,保存到session中 session.setAttribute("SMS_" + phone, code); // //4.发送验证码到进店用户的手机 // smsTemplate.sendSms(phone, code); return ResultInfo.success(null); } /* 用户新用户注册+老用户登录: * 这个接口兼具用户注册和登录的功能,实现思路是这样的: * 接收用户输入的手机号和验证码,首先判断验证码是否正确,如果不正确直接给出错误提示 * 如果验证码没问题,接下来,验证用户的手机号在数据库是否存在 * 如果存在,表示老用户在进行登录操作,并且登录成功了 * 如果不存在,表示新用户在进行注册操作,需要将用户信息保存到user表中 * 将此人的信息保存到session * */ @PostMapping("/user/login") public ResultInfo login(@RequestBody Map<String, String> map) { String phone = map.get("phone"); String code = map.get("code"); //通过用户发送的phone,获取到session中的code String codeFromSession = (String) session.getAttribute("SMS_" + phone); log.info("登录时用户输入的验证码为:{}---手机号{}", codeFromSession, phone); //校验code 前端传入code和session中保存code是否一致? if (!StringUtils.equals(code, codeFromSession) || StringUtils.isEmpty(code) || StringUtils.isEmpty(codeFromSession)) { return ResultInfo.error("验证码不对"); } // User currentUser = userService.findByPhone(phone); if (currentUser == null) { //3-2 没查到,代表新用户在注册 currentUser = new User(); currentUser.setPhone(phone); currentUser.setStatus(1);//激活 userService.save(currentUser); } //4. 将user信息保存到session中(注意: 这个键必须跟拦截器中使用的键一致) session.setAttribute("SESSION_USER", currentUser); return ResultInfo.success(currentUser); } }