spring boot整合MySQL数据库以及代码生成器

spring boot整合MySQL数据库以及代码生成器

项目结构

2021-03-09_112922.png
  • application.properties 配置
server.port=8001

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://IP:PORT/数据库名?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
spring.datasource.username=数据库用户名
spring.datasource.password=数据库密码

mybatis.type-aliases-package=com.louis.mango.domain
mybatis.mapper-locations=classpath:mapper/*Mapper.xml

spring.devtools.restart.additional-paths=src/main/java
  • pom表单


    4.0.0
    com.louis
    mango
    0.0.1-SNAPSHOT
    mango
    Demo project for Spring Boot
    
    
        org.springframework.boot
        spring-boot-starter-parent
        2.4.3
         
    
    
    
    
        1.8
        UTF-8
        UTF-8
    
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
        
        
            io.springfox
            springfox-swagger2
            2.6.1
        
        
            io.springfox
            springfox-swagger-ui
            2.6.1
        
        
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        
        
        
        
            mysql
            mysql-connector-java
        
        
        
            org.freemarker
            freemarker
            
        
            org.mybatis.generator
            mybatis-generator-core
            1.3.5
            test
        
        
            tk.mybatis
            mapper-spring-boot-starter
            1.2.0
        
        
            org.apache.commons
            commons-lang3
            
        
        
            com.alibaba
            fastjson
            1.2.39
        
        
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            RELEASE
        
        
        
        
            org.springframework.boot
            spring-boot-devtools
            true 
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


  • 数据库sql
/*
SQLyog Ultimate v12.09 (64 bit)
MySQL - 5.7.9 : Database - mango
*********************************************************************
*/


/*!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*/`mango` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `mango`;

/*Table structure for table `tb_config` */

DROP TABLE IF EXISTS `tb_config`;

CREATE TABLE `tb_config` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `value` varchar(100) NOT NULL COMMENT '数据值',
  `label` varchar(100) NOT NULL COMMENT '标签名',
  `type` varchar(100) NOT NULL COMMENT '类型',
  `description` varchar(100) NOT NULL COMMENT '描述',
  `sort` decimal(10,0) NOT NULL COMMENT '排序(升序)',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `remarks` varchar(255) DEFAULT NULL COMMENT '备注信息',
  `del_flag` tinyint(4) DEFAULT '0' COMMENT '是否删除  -1:已删除  0:正常',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='系统配置表';

/*Data for the table `tb_config` */

insert  into `tb_config`(`id`,`value`,`label`,`type`,`description`,`sort`,`create_by`,`create_time`,`last_update_by`,`last_update_time`,`remarks`,`del_flag`) values (1,'#14889A','theme','color','主题色','0','admin','2018-09-23 19:52:54',NULL,NULL,'主题色',0);

/*Table structure for table `tb_dept` */

DROP TABLE IF EXISTS `tb_dept`;

CREATE TABLE `tb_dept` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `name` varchar(50) DEFAULT NULL COMMENT '机构名称',
  `parent_id` bigint(20) DEFAULT NULL COMMENT '上级机构ID,一级机构为0',
  `order_num` int(11) DEFAULT NULL COMMENT '排序',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `del_flag` tinyint(4) DEFAULT '0' COMMENT '是否删除  -1:已删除  0:正常',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='机构管理';

/*Data for the table `tb_dept` */

insert  into `tb_dept`(`id`,`name`,`parent_id`,`order_num`,`create_by`,`create_time`,`last_update_by`,`last_update_time`,`del_flag`) values (1,'轻尘集团',NULL,0,'admin','2018-09-23 19:35:22',NULL,NULL,0),(2,'牧尘集团',NULL,1,'admin','2018-09-23 19:35:55',NULL,NULL,0),(3,'三国集团',NULL,2,'admin','2018-09-23 19:36:24',NULL,NULL,0),(4,'上海分公司',2,0,'admin','2018-09-23 19:37:03',NULL,NULL,0),(5,'北京分公司',1,1,'admin','2018-09-23 19:37:17',NULL,NULL,0),(6,'北京分公司',2,1,'admin','2018-09-23 19:37:28',NULL,NULL,0),(7,'技术部',5,0,'admin','2018-09-23 19:38:00',NULL,NULL,0),(8,'技术部',4,0,'admin','2018-09-23 19:38:10',NULL,NULL,0),(9,'技术部',6,0,'admin','2018-09-23 19:38:17',NULL,NULL,0),(10,'市场部',5,0,'admin','2018-09-23 19:38:45',NULL,NULL,0),(11,'市场部',6,0,'admin','2018-09-23 19:39:01',NULL,NULL,0),(12,'魏国',3,0,'admin','2018-09-23 19:40:42',NULL,NULL,0),(13,'蜀国',3,1,'admin','2018-09-23 19:40:54',NULL,NULL,0),(14,'吴国',3,2,'admin','2018-09-23 19:41:04',NULL,NULL,0);

/*Table structure for table `tb_dict` */

DROP TABLE IF EXISTS `tb_dict`;

CREATE TABLE `tb_dict` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `value` varchar(100) NOT NULL COMMENT '数据值',
  `label` varchar(100) NOT NULL COMMENT '标签名',
  `type` varchar(100) NOT NULL COMMENT '类型',
  `description` varchar(100) NOT NULL COMMENT '描述',
  `sort` decimal(10,0) NOT NULL COMMENT '排序(升序)',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `remarks` varchar(255) DEFAULT NULL COMMENT '备注信息',
  `del_flag` tinyint(4) DEFAULT '0' COMMENT '是否删除  -1:已删除  0:正常',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='字典表';

/*Data for the table `tb_dict` */

insert  into `tb_dict`(`id`,`value`,`label`,`type`,`description`,`sort`,`create_by`,`create_time`,`last_update_by`,`last_update_time`,`remarks`,`del_flag`) values (1,'male','男','sex','性别','0','admin','2018-09-23 19:52:54',NULL,NULL,'性别',0),(2,'female','女','sex','性别','1','admin','2018-09-23 19:53:17',NULL,NULL,'性别',0);

/*Table structure for table `tb_log` */

DROP TABLE IF EXISTS `tb_log`;

CREATE TABLE `tb_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `user_name` varchar(50) DEFAULT NULL COMMENT '用户名',
  `operation` varchar(50) DEFAULT NULL COMMENT '用户操作',
  `method` varchar(200) DEFAULT NULL COMMENT '请求方法',
  `params` varchar(5000) DEFAULT NULL COMMENT '请求参数',
  `time` bigint(20) NOT NULL COMMENT '执行时长(毫秒)',
  `ip` varchar(64) DEFAULT NULL COMMENT 'IP地址',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2898 DEFAULT CHARSET=utf8 COMMENT='系统操作日志';

/*Data for the table `tb_log` */

insert  into `tb_log`(`id`,`user_name`,`operation`,`method`,`params`,`time`,`ip`,`create_by`,`create_time`,`last_update_by`,`last_update_time`) values (1,'admin',NULL,'com.louis.kitty.admin.sevice.impl.SysDictServiceImpl.findPage()','{\"columnFilters\":{\"label\":{\"name\":\"label\",\"value\":\"\"}},\"pageNum\":1,\"pageSize\":8}',4,'0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:16',NULL,NULL),(2,'admin',NULL,'com.louis.kitty.admin.sevice.impl.SysRoleServiceImpl.findPage()','{\"columnFilters\":{\"name\":{\"name\":\"name\",\"value\":\"\"}},\"pageNum\":1,\"pageSize\":8}',4,'0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:17',NULL,NULL),(3,'admin',NULL,'com.louis.kitty.admin.sevice.impl.SysUserServiceImpl.findPage()','{\"columnFilters\":{\"name\":{\"name\":\"name\",\"value\":\"\"}},\"pageNum\":1,\"pageSize\":8}',36,'0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:18',NULL,NULL),(4,'admin',NULL,'com.louis.kitty.admin.sevice.impl.SysDictServiceImpl.findPage()','{\"columnFilters\":{\"label\":{\"name\":\"label\",\"value\":\"\"}},\"pageNum\":1,\"pageSize\":8}',4,'0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:20',NULL,NULL),(5,'admin',NULL,'com.louis.kitty.admin.sevice.impl.SysRoleServiceImpl.findPage()','{\"columnFilters\":{\"name\":{\"name\":\"name\",\"value\":\"\"}},\"pageNum\":1,\"pageSize\":8}',4,'0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:20',NULL,NULL),(6,'admin',NULL,'com.louis.kitty.admin.sevice.impl.SysUserServiceImpl.findPage()','{\"columnFilters\":{\"name\":{\"name\":\"name\",\"value\":\"\"}},\"pageNum\":1,\"pageSize\":8}',27,'0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:21',NULL,NULL),(7,'admin',NULL,'com.louis.kitty.admin.sevice.impl.SysRoleServiceImpl.findPage()','{\"columnFilters\":{\"name\":{\"name\":\"name\",\"value\":\"\"}},\"pageNum\":1,\"pageSize\":8}',4,'0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:22',NULL,NULL),(8,'admin',NULL,'com.louis.kitty.admin.sevice.impl.SysDictServiceImpl.findPage()','{\"columnFilters\":{\"label\":{\"name\":\"label\",\"value\":\"\"}},\"pageNum\":1,\"pageSize\":8}',4,'0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:23',NULL,NULL),(2798,NULL,NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findByName()','\"admin\"',361,'0:0:0:0:0:0:0:1',NULL,NULL,NULL,NULL),(2799,NULL,NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findByName()','\"admin\"',4,'0:0:0:0:0:0:0:1',NULL,NULL,NULL,NULL),(2800,NULL,NULL,'com.louis.mango.admin.service.impl.SysMenuServiceImpl.findByUser()','\"admin\"',43,'0:0:0:0:0:0:0:1',NULL,NULL,NULL,NULL),(2801,NULL,NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findPermissions()','\"admin\"',49,'0:0:0:0:0:0:0:1',NULL,NULL,NULL,NULL),(2802,NULL,NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findByName()','\"admin\"',221,'0:0:0:0:0:0:0:1',NULL,NULL,NULL,NULL),(2803,NULL,NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findByName()','\"admin\"',3,'0:0:0:0:0:0:0:1',NULL,NULL,NULL,NULL),(2804,NULL,NULL,'com.louis.mango.admin.service.impl.SysMenuServiceImpl.findByUser()','\"admin\"',37,'0:0:0:0:0:0:0:1',NULL,NULL,NULL,NULL),(2805,NULL,NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findPermissions()','\"admin\"',43,'0:0:0:0:0:0:0:1',NULL,NULL,NULL,NULL),(2806,'admin',NULL,'com.louis.mango.admin.service.impl.SysLoginLogServiceImpl.writeLoginLog()','\"admin\"',138,'0:0:0:0:0:0:0:1','admin','2019-01-21 10:15:43',NULL,NULL),(2807,'admin',NULL,'com.louis.mango.admin.service.impl.SysMenuServiceImpl.findTree()','\"admin\"',15,'0:0:0:0:0:0:0:1','admin','2019-01-21 10:15:44',NULL,NULL),(2808,'admin',NULL,'com.louis.mango.admin.service.impl.SysMenuServiceImpl.findByUser()','\"admin\"',16,'0:0:0:0:0:0:0:1','admin','2019-01-21 10:15:44',NULL,NULL),(2809,'admin',NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findPermissions()','\"admin\"',22,'0:0:0:0:0:0:0:1','admin','2019-01-21 10:15:44',NULL,NULL),(2876,'admin',NULL,'com.louis.mango.admin.service.impl.SysLoginLogServiceImpl.findPage()','{\"pageNum\":1,\"pageSize\":9,\"params\":[{\"name\":\"userName\",\"value\":\"\"}]}',13,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:10',NULL,NULL),(2877,'admin',NULL,'com.louis.mango.admin.service.impl.SysRoleServiceImpl.findPage()','{\"pageNum\":1,\"pageSize\":9,\"params\":[{\"name\":\"name\",\"value\":\"\"}]}',15,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:13',NULL,NULL),(2878,'admin',NULL,'com.louis.mango.admin.service.impl.SysMenuServiceImpl.findTree()','null',10,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:13',NULL,NULL),(2879,'admin',NULL,'com.louis.mango.admin.service.impl.SysDeptServiceImpl.findTree()',NULL,3,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:14',NULL,NULL),(2880,'admin',NULL,'com.louis.mango.admin.service.impl.SysDeptServiceImpl.findTree()',NULL,2,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:14',NULL,NULL),(2881,'admin',NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findPage()','{\"pageNum\":1,\"pageSize\":9,\"params\":[{\"name\":\"name\",\"value\":\"\"}]}',49,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:14',NULL,NULL),(2882,'admin',NULL,'com.louis.mango.admin.service.impl.SysRoleServiceImpl.findAll()',NULL,1,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:14',NULL,NULL),(2883,'admin',NULL,'com.louis.mango.admin.service.impl.SysMenuServiceImpl.findTree()','null',3,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:15',NULL,NULL),(2884,'admin',NULL,'com.louis.mango.admin.service.impl.SysConfigServiceImpl.findPage()','{\"pageNum\":1,\"pageSize\":9,\"params\":[{\"name\":\"label\",\"value\":\"\"}]}',8,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:15',NULL,NULL),(2885,'admin',NULL,'com.louis.mango.admin.service.impl.SysLoginLogServiceImpl.findPage()','{\"pageNum\":1,\"pageSize\":9,\"params\":[{\"name\":\"userName\",\"value\":\"\"}]}',7,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:16',NULL,NULL),(2886,'admin',NULL,'com.louis.mango.admin.service.impl.SysDeptServiceImpl.findTree()',NULL,2,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:22',NULL,NULL),(2887,'admin',NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findPage()','{\"pageNum\":1,\"pageSize\":9,\"params\":[{\"name\":\"name\",\"value\":\"\"}]}',61,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:22',NULL,NULL),(2888,'admin',NULL,'com.louis.mango.admin.service.impl.SysRoleServiceImpl.findAll()',NULL,1,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:22',NULL,NULL),(2889,'admin',NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findPage()','{\"pageNum\":2,\"pageSize\":9,\"params\":[{\"name\":\"name\",\"value\":\"\"}]}',18,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:25',NULL,NULL),(2890,'admin',NULL,'com.louis.mango.admin.service.impl.SysRoleServiceImpl.findAll()',NULL,2,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:25',NULL,NULL),(2891,'admin',NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findPage()','{\"pageNum\":1,\"pageSize\":9,\"params\":[{\"name\":\"name\",\"value\":\"\"}]}',43,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:27',NULL,NULL),(2892,'admin',NULL,'com.louis.mango.admin.service.impl.SysRoleServiceImpl.findAll()',NULL,1,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:27',NULL,NULL),(2893,'admin',NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.createUserExcelFile()','{\"pageNum\":1,\"pageSize\":100000,\"params\":[{\"name\":\"name\",\"value\":\"\"}]}',1577,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:48:38',NULL,NULL),(2894,'admin',NULL,'com.louis.mango.admin.service.impl.SysDeptServiceImpl.findTree()',NULL,1,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:49:24',NULL,NULL),(2895,'admin',NULL,'com.louis.mango.admin.service.impl.SysUserServiceImpl.findPage()','{\"pageNum\":1,\"pageSize\":9,\"params\":[{\"name\":\"name\",\"value\":\"\"}]}',75,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:49:24',NULL,NULL),(2896,'admin',NULL,'com.louis.mango.admin.service.impl.SysRoleServiceImpl.findAll()',NULL,2,'0:0:0:0:0:0:0:1','admin','2019-01-22 14:49:24',NULL,NULL),(2897,'admin',NULL,'com.louis.kitty.admin.sevice.impl.SysDictServiceImpl.findPage()','{\"columnFilters\":{\"label\":{\"name\":\"label\",\"value\":\"\"}},\"pageNum\":1,\"pageSize\":8}',4,'0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:16',NULL,NULL);

/*Table structure for table `tb_login_log` */

DROP TABLE IF EXISTS `tb_login_log`;

CREATE TABLE `tb_login_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `user_name` varchar(50) DEFAULT NULL COMMENT '用户名',
  `status` varchar(50) DEFAULT NULL COMMENT '登录状态(online:在线,登录初始状态,方便统计在线人数;login:退出登录后将online置为login;logout:退出登录)',
  `ip` varchar(64) DEFAULT NULL COMMENT 'IP地址',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2804 DEFAULT CHARSET=utf8 COMMENT='系统登录日志';

/*Data for the table `tb_login_log` */

insert  into `tb_login_log`(`id`,`user_name`,`status`,`ip`,`create_by`,`create_time`,`last_update_by`,`last_update_time`) values (1,'admin','login','0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:16',NULL,NULL),(2,'admin','logout','0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:17',NULL,NULL),(3,'admin','login','0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:18',NULL,NULL),(4,'admin','logout','0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:20',NULL,NULL),(5,'admin','login','0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:20',NULL,NULL),(6,'admin','logout','0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:21',NULL,NULL),(7,'admin','login','0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:22',NULL,NULL),(8,'admin','login','0:0:0:0:0:0:0:1','admin','2018-09-23 19:54:23','admin','2019-01-21 10:15:43'),(2798,'admin','logout','0:0:0:0:0:0:0:1','admin','2019-01-21 10:15:43',NULL,NULL),(2799,'admin','login','0:0:0:0:0:0:0:1','admin','2019-01-21 10:15:43','admin','2019-01-21 10:16:54'),(2800,'admin','logout','0:0:0:0:0:0:0:1','admin','2019-01-21 10:16:54',NULL,NULL),(2801,'admin','login','0:0:0:0:0:0:0:1','admin','2019-01-21 10:16:54','admin','2019-01-22 14:43:09'),(2802,'admin','logout','0:0:0:0:0:0:0:1','admin','2019-01-22 14:43:09',NULL,NULL),(2803,'admin','online','0:0:0:0:0:0:0:1','admin','2019-01-22 14:43:09',NULL,NULL);

/*Table structure for table `tb_menu` */

DROP TABLE IF EXISTS `tb_menu`;

CREATE TABLE `tb_menu` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `name` varchar(50) DEFAULT NULL COMMENT '菜单名称',
  `parent_id` bigint(20) DEFAULT NULL COMMENT '父菜单ID,一级菜单为0',
  `url` varchar(200) DEFAULT NULL COMMENT '菜单URL,类型:1.普通页面(如用户管理, /sys/user) 2.嵌套完整外部页面,以http(s)开头的链接 3.嵌套服务器页面,使用iframe:前缀+目标URL(如SQL监控, iframe:/druid/login.html, iframe:前缀会替换成服务器地址)',
  `perms` varchar(500) DEFAULT NULL COMMENT '授权(多个用逗号分隔,如:sys:user:add,sys:user:edit)',
  `type` int(11) DEFAULT NULL COMMENT '类型   0:目录   1:菜单   2:按钮',
  `icon` varchar(50) DEFAULT NULL COMMENT '菜单图标',
  `order_num` int(11) DEFAULT NULL COMMENT '排序',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `del_flag` tinyint(4) DEFAULT '0' COMMENT '是否删除  -1:已删除  0:正常',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8 COMMENT='菜单管理';

/*Data for the table `tb_menu` */

insert  into `tb_menu`(`id`,`name`,`parent_id`,`url`,`perms`,`type`,`icon`,`order_num`,`create_by`,`create_time`,`last_update_by`,`last_update_time`,`del_flag`) values (1,'系统管理',0,NULL,NULL,0,'el-icon-setting',0,NULL,NULL,NULL,NULL,0),(2,'用户管理',1,'/sys/user',NULL,1,'el-icon-service',1,NULL,NULL,NULL,NULL,0),(3,'查看',2,NULL,'sys:user:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(4,'新增',2,NULL,'sys:user:add',2,NULL,0,NULL,NULL,NULL,NULL,0),(5,'修改',2,NULL,'sys:user:edit',2,NULL,0,NULL,NULL,NULL,NULL,0),(6,'删除',2,NULL,'sys:user:delete',2,NULL,0,NULL,NULL,NULL,NULL,0),(7,'机构管理',1,'/sys/dept',NULL,1,'el-icon-news',2,NULL,NULL,NULL,NULL,0),(8,'查看',7,NULL,'sys:dept:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(9,'新增',7,NULL,'sys:dept:add',2,NULL,0,NULL,NULL,NULL,NULL,0),(10,'修改',7,NULL,'sys:dept:edit',2,NULL,0,NULL,NULL,NULL,NULL,0),(11,'删除',7,NULL,'sys:dept:delete',2,NULL,0,NULL,NULL,NULL,NULL,0),(12,'角色管理',1,'/sys/role',NULL,1,'el-icon-view',4,NULL,NULL,NULL,NULL,0),(13,'查看',12,NULL,'sys:role:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(14,'新增',12,NULL,'sys:role:add',2,NULL,0,NULL,NULL,NULL,NULL,0),(15,'修改',12,NULL,'sys:role:edit',2,NULL,0,NULL,NULL,NULL,NULL,0),(16,'删除',12,NULL,'sys:role:delete',2,NULL,0,NULL,NULL,NULL,NULL,0),(17,'菜单管理',1,'/sys/menu',NULL,1,'el-icon-menu',5,NULL,NULL,NULL,NULL,0),(18,'查看',17,NULL,'sys:menu:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(19,'新增',17,NULL,'sys:menu:add',2,NULL,0,NULL,NULL,NULL,NULL,0),(20,'修改',17,NULL,'sys:menu:edit',2,NULL,0,NULL,NULL,NULL,NULL,0),(21,'删除',17,NULL,'sys:menu:delete',2,NULL,0,NULL,NULL,NULL,NULL,0),(22,'字典管理',1,'/sys/dict',NULL,1,'el-icon-edit-outline',7,NULL,NULL,NULL,NULL,0),(23,'查看',22,NULL,'sys:dict:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(24,'新增',22,NULL,'sys:dict:add',2,NULL,0,NULL,NULL,NULL,NULL,0),(25,'修改',22,NULL,'sys:dict:edit',2,NULL,0,NULL,NULL,NULL,NULL,0),(26,'删除',22,NULL,'sys:dict:delete',2,NULL,0,NULL,NULL,NULL,NULL,0),(27,'系统配置',1,'/sys/config',NULL,1,'el-icon-edit-outline',7,NULL,NULL,NULL,NULL,0),(28,'查看',27,NULL,'sys:config:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(29,'新增',27,NULL,'sys:config:add',2,NULL,0,NULL,NULL,NULL,NULL,0),(30,'修改',27,NULL,'sys:config:edit',2,NULL,0,NULL,NULL,NULL,NULL,0),(31,'删除',27,NULL,'sys:config:delete',2,NULL,0,NULL,NULL,NULL,NULL,0),(32,'登录日志',1,'/sys/loginlog',NULL,1,'el-icon-info',8,NULL,NULL,'admin','2018-09-23 19:32:28',0),(33,'查看',32,NULL,'sys:loginlog:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(34,'删除',32,NULL,'sys:loginlog:delete',2,NULL,0,NULL,NULL,NULL,NULL,0),(35,'操作日志',1,'/sys/log',NULL,1,'el-icon-info',8,NULL,NULL,'admin','2018-09-23 19:32:28',0),(36,'查看',35,NULL,'sys:log:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(37,'删除',35,NULL,'sys:log:delete',2,NULL,0,NULL,NULL,NULL,NULL,0),(38,'系统监控',0,'','',0,'el-icon-info',4,'admin','2018-12-27 10:57:29','admin','2019-01-10 17:31:04',0),(39,'数据监控',38,'http://127.0.0.1:8001/druid/login.html',NULL,1,'el-icon-warning',0,NULL,NULL,'admin','2018-12-27 11:03:45',0),(40,'查看',39,NULL,'sys:druid:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(41,'服务监控',38,'http://127.0.0.1:8000/',NULL,1,'el-icon-view',1,'admin','2018-11-02 20:02:15','admin','2018-12-27 11:03:53',0),(42,'查看',41,NULL,'sys:monitor:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(43,'服务治理',0,'','',0,'el-icon-service',2,'admin','2018-12-27 11:05:48','admin','2018-12-27 11:06:39',0),(44,'注册中心',43,'http://127.0.0.1:8500',NULL,1,' el-icon-view',0,'admin','2018-11-03 11:06:48','admin','2018-12-27 11:08:11',0),(45,'查看',44,NULL,'sys:consul:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(46,'接口文档',0,'http://127.0.0.1:8001/swagger-ui.html',NULL,1,'el-icon-document',3,NULL,NULL,'admin','2018-12-27 11:04:18',0),(47,'查看',46,NULL,'sys:swagger:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(48,'代码生成',0,'/generator/generator','',1,'el-icon-star-on',5,'admin','2018-11-15 14:39:30','admin','2018-11-15 14:56:18',0),(49,'查看',48,NULL,'sys:generator:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(50,'在线用户',0,'/sys/online','',1,'el-icon-view',5,'admin','2018-11-15 14:39:30','admin','2018-11-15 14:56:18',0),(51,'查看',50,NULL,'sys:online:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(52,'使用案例',0,NULL,NULL,0,'el-icon-picture-outline',6,NULL,NULL,'admin','2018-11-15 14:39:43',0),(53,'国际化',52,'/demo/i18n',NULL,1,'el-icon-edit',1,NULL,NULL,NULL,NULL,0),(54,'查看',53,NULL,'sys:dict:view',2,NULL,0,NULL,NULL,NULL,NULL,0),(55,'换皮肤',52,'/demo/theme',NULL,1,'el-icon-picture',2,NULL,NULL,NULL,NULL,0),(56,'查看',55,NULL,'sys:dict:view',2,NULL,0,NULL,NULL,NULL,NULL,0);

/*Table structure for table `tb_role` */

DROP TABLE IF EXISTS `tb_role`;

CREATE TABLE `tb_role` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `name` varchar(100) DEFAULT NULL COMMENT '角色名称',
  `remark` varchar(100) DEFAULT NULL COMMENT '备注',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `del_flag` tinyint(4) DEFAULT '0' COMMENT '是否删除  -1:已删除  0:正常',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='角色管理';

/*Data for the table `tb_role` */

insert  into `tb_role`(`id`,`name`,`remark`,`create_by`,`create_time`,`last_update_by`,`last_update_time`,`del_flag`) values (1,'admin','超级管理员','admin','2019-01-19 11:11:11','admin','2019-01-19 19:07:18',0),(2,'mng','项目经理','admin','2019-01-19 11:11:11','admin','2019-01-19 11:39:28',0),(3,'dev','开发人员','admin','2019-01-19 11:11:11','admin','2019-01-19 11:39:28',0),(4,'test','测试人员','admin','2019-01-19 11:11:11','admin','2019-01-19 11:11:11',0);

/*Table structure for table `tb_role_dept` */

DROP TABLE IF EXISTS `tb_role_dept`;

CREATE TABLE `tb_role_dept` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `role_id` bigint(20) DEFAULT NULL COMMENT '角色ID',
  `dept_id` bigint(20) DEFAULT NULL COMMENT '机构ID',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='角色机构';

/*Data for the table `tb_role_dept` */

insert  into `tb_role_dept`(`id`,`role_id`,`dept_id`,`create_by`,`create_time`,`last_update_by`,`last_update_time`) values (1,1,1,'admin','2019-01-11 08:30:37','admin','2019-01-11 08:30:25'),(2,2,2,'admin','2019-01-11 08:31:01','admin','2019-01-11 08:31:04'),(3,3,3,'admin','2019-01-11 08:31:18','admin','2019-01-11 08:31:21');

/*Table structure for table `tb_role_menu` */

DROP TABLE IF EXISTS `tb_role_menu`;

CREATE TABLE `tb_role_menu` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `role_id` bigint(20) DEFAULT NULL COMMENT '角色ID',
  `menu_id` bigint(20) DEFAULT NULL COMMENT '菜单ID',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=623 DEFAULT CHARSET=utf8 COMMENT='角色菜单';

/*Data for the table `tb_role_menu` */

insert  into `tb_role_menu`(`id`,`role_id`,`menu_id`,`create_by`,`create_time`,`last_update_by`,`last_update_time`) values (431,8,1,'admin','2018-09-23 19:55:08',NULL,NULL),(432,8,2,'admin','2018-09-23 19:55:08',NULL,NULL),(433,8,9,'admin','2018-09-23 19:55:08',NULL,NULL),(434,8,3,'admin','2018-09-23 19:55:08',NULL,NULL),(435,8,13,'admin','2018-09-23 19:55:08',NULL,NULL),(436,8,4,'admin','2018-09-23 19:55:08',NULL,NULL),(437,8,17,'admin','2018-09-23 19:55:08',NULL,NULL),(438,8,5,'admin','2018-09-23 19:55:08',NULL,NULL),(439,8,21,'admin','2018-09-23 19:55:08',NULL,NULL),(440,8,7,'admin','2018-09-23 19:55:08',NULL,NULL),(441,8,31,'admin','2018-09-23 19:55:08',NULL,NULL),(442,8,8,'admin','2018-09-23 19:55:08',NULL,NULL),(443,8,6,'admin','2018-09-23 19:55:08',NULL,NULL),(444,8,35,'admin','2018-09-23 19:55:08',NULL,NULL),(469,2,1,NULL,NULL,NULL,NULL),(470,2,2,NULL,NULL,NULL,NULL),(471,2,3,NULL,NULL,NULL,NULL),(472,2,4,NULL,NULL,NULL,NULL),(473,2,5,NULL,NULL,NULL,NULL),(474,2,6,NULL,NULL,NULL,NULL),(475,2,7,NULL,NULL,NULL,NULL),(476,2,8,NULL,NULL,NULL,NULL),(477,2,9,NULL,NULL,NULL,NULL),(478,2,10,NULL,NULL,NULL,NULL),(479,2,11,NULL,NULL,NULL,NULL),(480,2,12,NULL,NULL,NULL,NULL),(481,2,13,NULL,NULL,NULL,NULL),(482,2,14,NULL,NULL,NULL,NULL),(483,2,15,NULL,NULL,NULL,NULL),(484,2,16,NULL,NULL,NULL,NULL),(485,2,17,NULL,NULL,NULL,NULL),(486,2,18,NULL,NULL,NULL,NULL),(487,2,19,NULL,NULL,NULL,NULL),(488,2,20,NULL,NULL,NULL,NULL),(489,2,21,NULL,NULL,NULL,NULL),(490,2,22,NULL,NULL,NULL,NULL),(491,2,23,NULL,NULL,NULL,NULL),(492,2,24,NULL,NULL,NULL,NULL),(493,2,25,NULL,NULL,NULL,NULL),(494,2,26,NULL,NULL,NULL,NULL),(495,2,27,NULL,NULL,NULL,NULL),(496,2,28,NULL,NULL,NULL,NULL),(497,2,29,NULL,NULL,NULL,NULL),(498,2,30,NULL,NULL,NULL,NULL),(499,2,31,NULL,NULL,NULL,NULL),(500,2,32,NULL,NULL,NULL,NULL),(501,2,33,NULL,NULL,NULL,NULL),(502,2,34,NULL,NULL,NULL,NULL),(503,2,35,NULL,NULL,NULL,NULL),(504,2,36,NULL,NULL,NULL,NULL),(505,2,37,NULL,NULL,NULL,NULL),(506,2,43,NULL,NULL,NULL,NULL),(507,2,44,NULL,NULL,NULL,NULL),(508,2,45,NULL,NULL,NULL,NULL),(509,2,46,NULL,NULL,NULL,NULL),(510,2,47,NULL,NULL,NULL,NULL),(511,2,38,NULL,NULL,NULL,NULL),(512,2,39,NULL,NULL,NULL,NULL),(513,2,40,NULL,NULL,NULL,NULL),(514,2,41,NULL,NULL,NULL,NULL),(515,2,42,NULL,NULL,NULL,NULL),(516,2,48,NULL,NULL,NULL,NULL),(517,2,49,NULL,NULL,NULL,NULL),(518,2,50,NULL,NULL,NULL,NULL),(519,2,51,NULL,NULL,NULL,NULL),(520,2,52,NULL,NULL,NULL,NULL),(521,2,53,NULL,NULL,NULL,NULL),(522,2,54,NULL,NULL,NULL,NULL),(523,2,55,NULL,NULL,NULL,NULL),(524,2,56,NULL,NULL,NULL,NULL),(572,3,1,'admin','2019-01-22 14:45:28',NULL,NULL),(573,3,2,'admin','2019-01-22 14:45:28',NULL,NULL),(574,3,3,'admin','2019-01-22 14:45:28',NULL,NULL),(575,3,4,'admin','2019-01-22 14:45:28',NULL,NULL),(576,3,5,'admin','2019-01-22 14:45:28',NULL,NULL),(577,3,6,'admin','2019-01-22 14:45:28',NULL,NULL),(578,3,7,'admin','2019-01-22 14:45:28',NULL,NULL),(579,3,8,'admin','2019-01-22 14:45:28',NULL,NULL),(580,3,12,'admin','2019-01-22 14:45:28',NULL,NULL),(581,3,13,'admin','2019-01-22 14:45:28',NULL,NULL),(582,3,17,'admin','2019-01-22 14:45:28',NULL,NULL),(583,3,18,'admin','2019-01-22 14:45:28',NULL,NULL),(584,3,22,'admin','2019-01-22 14:45:28',NULL,NULL),(585,3,23,'admin','2019-01-22 14:45:28',NULL,NULL),(586,3,24,'admin','2019-01-22 14:45:28',NULL,NULL),(587,3,25,'admin','2019-01-22 14:45:28',NULL,NULL),(588,3,26,'admin','2019-01-22 14:45:28',NULL,NULL),(589,3,27,'admin','2019-01-22 14:45:28',NULL,NULL),(590,3,28,'admin','2019-01-22 14:45:28',NULL,NULL),(591,3,29,'admin','2019-01-22 14:45:28',NULL,NULL),(592,3,30,'admin','2019-01-22 14:45:28',NULL,NULL),(593,3,31,'admin','2019-01-22 14:45:28',NULL,NULL),(594,3,32,'admin','2019-01-22 14:45:28',NULL,NULL),(595,3,33,'admin','2019-01-22 14:45:28',NULL,NULL),(596,3,35,'admin','2019-01-22 14:45:28',NULL,NULL),(597,3,36,'admin','2019-01-22 14:45:28',NULL,NULL),(598,3,43,'admin','2019-01-22 14:45:28',NULL,NULL),(599,3,44,'admin','2019-01-22 14:45:28',NULL,NULL),(600,3,45,'admin','2019-01-22 14:45:28',NULL,NULL),(601,3,38,'admin','2019-01-22 14:45:28',NULL,NULL),(602,3,39,'admin','2019-01-22 14:45:28',NULL,NULL),(603,3,40,'admin','2019-01-22 14:45:28',NULL,NULL),(604,3,41,'admin','2019-01-22 14:45:28',NULL,NULL),(605,3,42,'admin','2019-01-22 14:45:28',NULL,NULL),(606,3,50,'admin','2019-01-22 14:45:28',NULL,NULL),(607,3,51,'admin','2019-01-22 14:45:28',NULL,NULL),(608,4,1,'admin','2019-01-22 14:46:44',NULL,NULL),(609,4,2,'admin','2019-01-22 14:46:44',NULL,NULL),(610,4,3,'admin','2019-01-22 14:46:44',NULL,NULL),(611,4,7,'admin','2019-01-22 14:46:44',NULL,NULL),(612,4,8,'admin','2019-01-22 14:46:44',NULL,NULL),(613,4,17,'admin','2019-01-22 14:46:44',NULL,NULL),(614,4,18,'admin','2019-01-22 14:46:44',NULL,NULL),(615,4,32,'admin','2019-01-22 14:46:44',NULL,NULL),(616,4,33,'admin','2019-01-22 14:46:44',NULL,NULL),(617,4,35,'admin','2019-01-22 14:46:44',NULL,NULL),(618,4,36,'admin','2019-01-22 14:46:44',NULL,NULL),(619,4,46,'admin','2019-01-22 14:46:44',NULL,NULL),(620,4,47,'admin','2019-01-22 14:46:44',NULL,NULL),(621,4,50,'admin','2019-01-22 14:46:44',NULL,NULL),(622,4,51,'admin','2019-01-22 14:46:44',NULL,NULL);

/*Table structure for table `tb_user` */

DROP TABLE IF EXISTS `tb_user`;

CREATE TABLE `tb_user` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `name` varchar(50) NOT NULL COMMENT '用户名',
  `nick_name` varchar(150) DEFAULT NULL COMMENT '昵称',
  `avatar` varchar(150) DEFAULT NULL COMMENT '头像',
  `password` varchar(100) DEFAULT NULL COMMENT '密码',
  `salt` varchar(40) DEFAULT NULL COMMENT '加密盐',
  `email` varchar(100) DEFAULT NULL COMMENT '邮箱',
  `mobile` varchar(100) DEFAULT NULL COMMENT '手机号',
  `status` tinyint(4) DEFAULT NULL COMMENT '状态  0:禁用   1:正常',
  `dept_id` bigint(20) DEFAULT NULL COMMENT '机构ID',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `del_flag` tinyint(4) DEFAULT '0' COMMENT '是否删除  -1:已删除  0:正常',
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8 COMMENT='用户管理';

/*Data for the table `tb_user` */

insert  into `tb_user`(`id`,`name`,`nick_name`,`avatar`,`password`,`salt`,`email`,`mobile`,`status`,`dept_id`,`create_by`,`create_time`,`last_update_by`,`last_update_time`,`del_flag`) values (1,'admin','超管',NULL,'bd1718f058d8a02468134432b8656a86','YzcmCZNvbXocrsz9dm8e','[email protected]','13612345678',1,4,'admin','2018-08-14 11:11:11','admin','2018-08-14 11:11:11',0),(22,'liubei','刘备',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',1,7,'admin','2018-09-23 19:43:00','admin','2019-01-10 11:41:13',0),(23,'zhaoyun','赵云',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',1,7,'admin','2018-09-23 19:43:44','admin','2018-09-23 19:43:52',0),(24,'zhugeliang','诸葛亮',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',7,11,'admin','2018-09-23 19:44:23','admin','2018-09-23 19:44:29',0),(25,'caocao','曹操',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',1,8,'admin','2018-09-23 19:45:32','admin','2019-01-10 17:59:14',0),(26,'dianwei','典韦',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',1,10,'admin','2018-09-23 19:45:48','admin','2018-09-23 19:45:57',0),(27,'xiahoudun','夏侯惇',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',1,8,'admin','2018-09-23 19:46:09','admin','2018-09-23 19:46:17',0),(28,'xunyu','荀彧',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',1,10,'admin','2018-09-23 19:46:38','admin','2018-11-04 15:33:17',0),(29,'sunquan','孙权',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',1,10,'admin','2018-09-23 19:46:54','admin','2018-09-23 19:47:03',0),(30,'zhouyu','周瑜',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',1,11,'admin','2018-09-23 19:47:28','admin','2018-09-23 19:48:04',0),(31,'luxun','陆逊',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',1,11,'admin','2018-09-23 19:47:44','admin','2018-09-23 19:47:58',0),(32,'huanggai','黄盖',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','[email protected]','13889700023',1,11,'admin','2018-09-23 19:48:38','admin','2018-09-23 19:49:02',0);

/*Table structure for table `tb_user_role` */

DROP TABLE IF EXISTS `tb_user_role`;

CREATE TABLE `tb_user_role` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `user_id` bigint(20) DEFAULT NULL COMMENT '用户ID',
  `role_id` bigint(20) DEFAULT NULL COMMENT '角色ID',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `last_update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  `last_update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8 COMMENT='用户角色';

/*Data for the table `tb_user_role` */

insert  into `tb_user_role`(`id`,`user_id`,`role_id`,`create_by`,`create_time`,`last_update_by`,`last_update_time`) values (1,1,1,NULL,NULL,NULL,NULL),(2,2,1,NULL,NULL,NULL,NULL),(26,5,3,NULL,NULL,NULL,NULL),(33,6,2,NULL,NULL,NULL,NULL),(34,4,2,NULL,NULL,NULL,NULL),(35,9,2,NULL,NULL,NULL,NULL),(36,10,3,NULL,NULL,NULL,NULL),(37,11,2,NULL,NULL,NULL,NULL),(38,12,3,NULL,NULL,NULL,NULL),(39,15,2,NULL,NULL,NULL,NULL),(41,16,3,NULL,NULL,NULL,NULL),(42,8,2,NULL,NULL,NULL,NULL),(43,7,4,NULL,NULL,NULL,NULL),(45,18,2,NULL,NULL,NULL,NULL),(46,17,3,NULL,NULL,NULL,NULL),(47,3,4,NULL,NULL,NULL,NULL),(48,21,2,NULL,NULL,NULL,NULL),(57,31,2,NULL,NULL,NULL,NULL),(58,30,2,NULL,NULL,NULL,NULL),(59,32,3,NULL,NULL,NULL,NULL),(73,33,8,NULL,NULL,NULL,NULL),(74,25,8,NULL,NULL,NULL,NULL),(75,25,2,NULL,NULL,NULL,NULL),(80,22,2,NULL,NULL,NULL,NULL),(81,23,3,NULL,NULL,NULL,NULL),(82,24,4,NULL,NULL,NULL,NULL),(83,26,3,NULL,NULL,NULL,NULL),(85,29,2,NULL,NULL,NULL,NULL),(86,28,4,NULL,NULL,NULL,NULL),(87,27,3,NULL,NULL,NULL,NULL);

/*!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 */;

  1. MangoApplication
package com.louis.mango;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = {"com.louis.mango"})
public class MangoApplication {

    public static void main(String[] args) {
        SpringApplication.run(MangoApplication.class, args);
    }
}

2.MybatisConfig

package com.louis.mango.config;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import tk.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

@Configuration
@MapperScan("com.louis.mango.**.dao")//扫描DAO
public class MybatisConfig {
    @Autowired
    private DataSource dataSource;
    
    @Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception{
        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
        sessionFactoryBean.setDataSource(dataSource);
        sessionFactoryBean.setTypeAliasesPackage("com.louis.mango.**.model");
        
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        sessionFactoryBean.setMapperLocations(resolver.getResources("classpath*:**/sqlmap/*.xml"));
        return sessionFactoryBean.getObject();
    }
}

3.SwaggerConfig

package com.louis.mango.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any()).build();
        
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().build();
    }
}

4.CodeGenerator 代码生成器

package com.louis.mango.generator;

import com.google.common.base.CaseFormat;
import freemarker.template.TemplateExceptionHandler;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.*;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.louis.mango.core.ProjectConstant.*;

/**
 * 代码生成器,根据数据表名称生成对应的Model、Mapper、Service、Controller简化开发。
 */
public class CodeGenerator {
    //JDBC配置,请修改为你项目的实际配置
    private static final String JDBC_URL = "jdbc:mysql://localhost:3306/mango";
    private static final String JDBC_USERNAME = "数据库用户名";
    private static final String JDBC_PASSWORD = "数据库密码";
    private static final String JDBC_DIVER_CLASS_NAME = "com.mysql.jdbc.Driver";

    private static final String PROJECT_PATH = System.getProperty("user.dir");//项目在硬盘上的基础路径
    private static final String TEMPLATE_FILE_PATH = PROJECT_PATH + "/src/test/resources/generator/template";//模板位置

    private static final String JAVA_PATH = "/src/main/java"; //java文件路径
    private static final String RESOURCES_PATH = "/src/main/resources";//资源文件路径

    private static final String PACKAGE_PATH_SERVICE = packageConvertPath(SERVICE_PACKAGE);//生成的Service存放路径
    private static final String PACKAGE_PATH_SERVICE_IMPL = packageConvertPath(SERVICE_IMPL_PACKAGE);//生成的Service实现存放路径
    private static final String PACKAGE_PATH_CONTROLLER = packageConvertPath(CONTROLLER_PACKAGE);//生成的Controller存放路径

    private static final String AUTHOR = "CodeGenerator";//@author
    private static final String DATE = new SimpleDateFormat("yyyy/MM/dd").format(new Date());//@date

    public static void main(String[] args) {
        genCode("数据库表名1");
        genCode("数据库表名2","数据库表名3");
    }

    /**
     * 通过数据表名称生成代码,Model 名称通过解析数据表名称获得,下划线转大驼峰的形式。
     * 如输入表名称 "t_user_detail" 将生成 TUserDetail、TUserDetailMapper、TUserDetailService ...
     * @param tableNames 数据表名称...
     */
    public static void genCode(String... tableNames) {
        for (String tableName : tableNames) {
            genCodeByCustomModelName(tableName, null);
        }
    }

    /**
     * 通过数据表名称,和自定义的 Model 名称生成代码
     * 如输入表名称 "t_user_detail" 和自定义的 Model 名称 "User" 将生成 User、UserMapper、UserService ...
     * @param tableName 数据表名称
     * @param modelName 自定义的 Model 名称
     */
    public static void genCodeByCustomModelName(String tableName, String modelName) {
        genModelAndMapper(tableName, modelName);
        genService(tableName, modelName);
        genController(tableName, modelName);
    }


    public static void genModelAndMapper(String tableName, String modelName) {
        System.err.println("tableName:"+tableName);
        System.err.println("modelName:"+modelName);
        Context context = new Context(ModelType.FLAT);
        context.setId("Potato");
        context.setTargetRuntime("MyBatis3Simple");
        context.addProperty(PropertyRegistry.CONTEXT_BEGINNING_DELIMITER, "`");
        context.addProperty(PropertyRegistry.CONTEXT_ENDING_DELIMITER, "`");
        context.addProperty(PropertyRegistry.CONTEXT_AUTO_DELIMIT_KEYWORDS, "key");

        JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();
        jdbcConnectionConfiguration.setConnectionURL(JDBC_URL);
        jdbcConnectionConfiguration.setUserId(JDBC_USERNAME);
        jdbcConnectionConfiguration.setPassword(JDBC_PASSWORD);
        jdbcConnectionConfiguration.setDriverClass(JDBC_DIVER_CLASS_NAME);
        context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);

        PluginConfiguration pluginConfiguration = new PluginConfiguration();
        pluginConfiguration.setConfigurationType("tk.mybatis.mapper.generator.MapperPlugin");
        pluginConfiguration.addProperty("mappers", MAPPER_INTERFACE_REFERENCE);
        context.addPluginConfiguration(pluginConfiguration);

        JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = new JavaModelGeneratorConfiguration();
        javaModelGeneratorConfiguration.setTargetProject(PROJECT_PATH + JAVA_PATH);
        javaModelGeneratorConfiguration.setTargetPackage(MODEL_PACKAGE);
        context.setJavaModelGeneratorConfiguration(javaModelGeneratorConfiguration);

        SqlMapGeneratorConfiguration sqlMapGeneratorConfiguration = new SqlMapGeneratorConfiguration();
        sqlMapGeneratorConfiguration.setTargetProject(PROJECT_PATH + RESOURCES_PATH);
        sqlMapGeneratorConfiguration.setTargetPackage("mapper");
        context.setSqlMapGeneratorConfiguration(sqlMapGeneratorConfiguration);

        JavaClientGeneratorConfiguration javaClientGeneratorConfiguration = new JavaClientGeneratorConfiguration();
        javaClientGeneratorConfiguration.setTargetProject(PROJECT_PATH + JAVA_PATH);
        javaClientGeneratorConfiguration.setTargetPackage(MAPPER_PACKAGE);
        javaClientGeneratorConfiguration.setConfigurationType("XMLMAPPER");
        context.setJavaClientGeneratorConfiguration(javaClientGeneratorConfiguration);

        TableConfiguration tableConfiguration = new TableConfiguration(context);
        tableConfiguration.setTableName(tableName);
        if (StringUtils.isNotEmpty(modelName))tableConfiguration.setDomainObjectName(modelName);
        tableConfiguration.setGeneratedKey(new GeneratedKey("id", "Mysql", true, null));
        tableConfiguration.setAllColumnDelimitingEnabled(true);
        context.addTableConfiguration(tableConfiguration);

        System.err.println(PROJECT_PATH + RESOURCES_PATH);
        List warnings;
        MyBatisGenerator generator;
        try {
            Configuration config = new Configuration();
            config.addContext(context);
            config.validate();

            boolean overwrite = true;
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            warnings = new ArrayList();
            generator = new MyBatisGenerator(config, callback, warnings);
            generator.generate(null);
        } catch (Exception e) {
            throw new RuntimeException("生成Model和Mapper失败", e);
        }

        if (generator.getGeneratedJavaFiles().isEmpty() || generator.getGeneratedXmlFiles().isEmpty()) {
            throw new RuntimeException("生成Model和Mapper失败:" + warnings);
        }
        if (StringUtils.isEmpty(modelName)) modelName = tableNameConvertUpperCamel(tableName);
        System.out.println(modelName + ".java 生成成功");
        System.out.println(modelName + "Mapper.java 生成成功");
        System.out.println(modelName + "Mapper.xml 生成成功");
    }

    public static void genService(String tableName, String modelName) {
        try {
            freemarker.template.Configuration cfg = getConfiguration();

            Map data = new HashMap<>();
            data.put("date", DATE);
            data.put("author", AUTHOR);
            String modelNameUpperCamel = StringUtils.isEmpty(modelName) ? tableNameConvertUpperCamel(tableName) : modelName;
            data.put("modelNameUpperCamel", modelNameUpperCamel);
            data.put("modelNameLowerCamel", tableNameConvertLowerCamel(tableName));
            data.put("basePackage", BASE_PACKAGE);

            File file = new File(PROJECT_PATH + JAVA_PATH + PACKAGE_PATH_SERVICE + modelNameUpperCamel + "Service.java");
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            cfg.getTemplate("service.ftl").process(data,
                    new FileWriter(file));
            System.out.println(modelNameUpperCamel + "Service.java 生成成功");

            File file1 = new File(PROJECT_PATH + JAVA_PATH + PACKAGE_PATH_SERVICE_IMPL + modelNameUpperCamel + "ServiceImpl.java");
            if (!file1.getParentFile().exists()) {
                file1.getParentFile().mkdirs();
            }
            cfg.getTemplate("service-impl.ftl").process(data,
                    new FileWriter(file1));
            System.out.println(modelNameUpperCamel + "ServiceImpl.java 生成成功");
        } catch (Exception e) {
            throw new RuntimeException("生成Service失败", e);
        }
    }

    public static void genController(String tableName, String modelName) {
        try {
            freemarker.template.Configuration cfg = getConfiguration();

            Map data = new HashMap<>();
            data.put("date", DATE);
            data.put("author", AUTHOR);
            String modelNameUpperCamel = StringUtils.isEmpty(modelName) ? tableNameConvertUpperCamel(tableName) : modelName;
            data.put("baseRequestMapping", modelNameConvertMappingPath(modelNameUpperCamel));
            data.put("modelNameUpperCamel", modelNameUpperCamel);
            data.put("modelNameLowerCamel", CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, modelNameUpperCamel));
            data.put("basePackage", BASE_PACKAGE);

            File file = new File(PROJECT_PATH + JAVA_PATH + PACKAGE_PATH_CONTROLLER + modelNameUpperCamel + "Controller.java");
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            //cfg.getTemplate("controller-restful.ftl").process(data, new FileWriter(file));
            cfg.getTemplate("controller.ftl").process(data, new FileWriter(file));

            System.out.println(modelNameUpperCamel + "Controller.java 生成成功");
        } catch (Exception e) {
            throw new RuntimeException("生成Controller失败", e);
        }

    }

    private static freemarker.template.Configuration getConfiguration() throws IOException {
        freemarker.template.Configuration cfg = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_23);
        cfg.setDirectoryForTemplateLoading(new File(TEMPLATE_FILE_PATH));
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
        return cfg;
    }

    private static String tableNameConvertLowerCamel(String tableName) {
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, tableName.toLowerCase());
    }

    private static String tableNameConvertUpperCamel(String tableName) {
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, tableName.toLowerCase());

    }

    private static String tableNameConvertMappingPath(String tableName) {
        tableName = tableName.toLowerCase();//兼容使用大写的表名
        return "/" + (tableName.contains("_") ? tableName.replaceAll("_", "/") : tableName);
    }

    private static String modelNameConvertMappingPath(String modelName) {
        String tableName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, modelName);
        return tableNameConvertMappingPath(tableName);
    }

    private static String packageConvertPath(String packageName) {
        return String.format("/%s/", packageName.contains(".") ? packageName.replaceAll("\\.", "/") : packageName);
    }

}

5.代码生成模板controller.ftl

package ${basePackage}.controller;
import ${basePackage}.core.Result;
import ${basePackage}.core.ResultGenerator;
import ${basePackage}.model.${modelNameUpperCamel};
import ${basePackage}.service.${modelNameUpperCamel}Service;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
* Created by ${author} on ${date}.
*/
@RestController
@RequestMapping("/v1${baseRequestMapping}")
public class ${modelNameUpperCamel}Controller {
    
    @Resource
    private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @ApiOperation(value="创建${modelNameLowerCamel}", notes="根据${modelNameUpperCamel}对象创建")
    @ApiImplicitParam(name = "${modelNameLowerCamel}", value = "${modelNameUpperCamel}实体", required = true, dataType = "${modelNameUpperCamel}")
    @PostMapping("/add")
    public Result add(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.save(${modelNameLowerCamel});
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value="删除${modelNameLowerCamel}", notes="根据id来指定删除${modelNameLowerCamel}")
    @ApiImplicitParam(name = "id", paramType = "query", value = "${modelNameLowerCamel} ID", required = true, dataType = "Long")
    @PostMapping("/delete")
    public Result delete(@RequestParam Long id) {
        ${modelNameLowerCamel}Service.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value="更新${modelNameUpperCamel}", notes="根据id来指定更新对象,并根据传过来的${modelNameLowerCamel}信息来更新其详细信息")
    @ApiImplicitParam(name = "${modelNameLowerCamel}", value = "${modelNameUpperCamel}实体", required = true, dataType = "${modelNameUpperCamel}")
    @PostMapping("/update")
    public Result update(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.update(${modelNameLowerCamel});
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value="获取${modelNameUpperCamel}详细信息", notes="根据id来获取${modelNameUpperCamel}详细信息")
    @ApiImplicitParam(name = "id", paramType = "query", value = "${modelNameUpperCamel} ID", required = true, dataType = "Long")
    @PostMapping("/detail")
    public Result detail(@RequestParam Long id) {
        ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.findById(id);
        return ResultGenerator.genSuccessResult(${modelNameLowerCamel});
    }

    @ApiOperation(value="获取${modelNameUpperCamel}列表", notes="")
    @PostMapping("/page")
    public Result page(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer limit) {
        PageHelper.startPage(page, limit);
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
    
    @ApiOperation(value="获取${modelNameUpperCamel}列表", notes="来获取${modelNameUpperCamel}列表")
    @PostMapping("/list")
    public Result list() {
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.findAll();
        return ResultGenerator.genSuccessResult();
    }
}

6.代码生成模板mapper.ftl

package ${basePackage}.service;

import ${basePackage}.core.Mapper;
import ${basePackage}.model.${modelNameUpperCamel};
import java.util.List;

/**
 * Created by ${author} on ${date}.
 */
public interface ${modelNameUpperCamel}Mapper extends Mapper<${modelNameUpperCamel}> {

    
}

7.代码生成模板service-impl.ftl

package ${basePackage}.service.impl;

import ${basePackage}.dao.${modelNameUpperCamel}Mapper;
import ${basePackage}.model.${modelNameUpperCamel};
import ${basePackage}.service.${modelNameUpperCamel}Service;
import ${basePackage}.core.AbstractService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import tk.mybatis.mapper.entity.Condition;

import java.util.List;
import javax.annotation.Resource;


/**
 * Created by ${author} on ${date}.
 */
@Service
@Transactional
public class ${modelNameUpperCamel}ServiceImpl extends AbstractService<${modelNameUpperCamel}> implements ${modelNameUpperCamel}Service {
    @Resource
    private ${modelNameUpperCamel}Mapper ${modelNameLowerCamel}Mapper;

    
}

8.代码生成模板service.ftl

package ${basePackage}.service;

import ${basePackage}.model.${modelNameUpperCamel};
import ${basePackage}.core.Service;
import java.util.List;

/**
 * Created by ${author} on ${date}.
 */
public interface ${modelNameUpperCamel}Service extends Service<${modelNameUpperCamel}> {

    
}

9.代码生成核心业务AbstractService

package com.louis.mango.core;


import org.apache.ibatis.exceptions.TooManyResultsException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import tk.mybatis.mapper.entity.Condition;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.util.List;

/**
 * 基于通用MyBatis Mapper插件的Service接口的实现
 */
@Transactional
public abstract class AbstractService implements Service {

    @Autowired
    protected Mapper mapper;

    private Class modelClass;    // 当前泛型真实类型的Class

    public AbstractService() {
        ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
        modelClass = (Class) pt.getActualTypeArguments()[0];
    }

    public void save(T model) {
        mapper.insertSelective(model);
    }

    public void save(List models) {
        mapper.insertList(models);
    }

    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public void deleteByIds(String ids) {
        mapper.deleteByIds(ids);
    }

    public void update(T model) {
        mapper.updateByPrimaryKeySelective(model);
    }

    public T findById(Long id) {
        System.err.println("2-----------"+id.getClass().getTypeName());
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public T findBy(String fieldName, Object value) throws TooManyResultsException {
        try {
            T model = modelClass.newInstance();
            Field field = modelClass.getDeclaredField(fieldName);
            field.setAccessible(true);
            field.set(model, value);
            return mapper.selectOne(model);
        } catch (ReflectiveOperationException e) {
            throw new ServiceException(e.getMessage(), e);
        }
    }

    public List findByIds(String ids) {
        return mapper.selectByIds(ids);
    }

    public List findByCondition(Condition condition) {
        return mapper.selectByCondition(condition);
    }

    public List findAll() {
        return mapper.selectAll();
    }
}

10.代码生成核心业务Mapper

package com.louis.mango.core;

import tk.mybatis.mapper.common.BaseMapper;
import tk.mybatis.mapper.common.ConditionMapper;
import tk.mybatis.mapper.common.IdsMapper;
import tk.mybatis.mapper.common.special.InsertListMapper;

/**
 * 定制版MyBatis Mapper插件接口,如需其他接口参考官方文档自行添加。
 */
public interface Mapper
        extends
        BaseMapper,
        ConditionMapper,
        IdsMapper,
        InsertListMapper {
}

11.代码生成核心业务ProjectConstant

package com.louis.mango.core;

/**
 * 项目常量
 */
public final class ProjectConstant {
    public static final String BASE_PACKAGE = "com.louis.mango";//项目基础包名称,根据自己公司的项目修改

    public static final String MODEL_PACKAGE = BASE_PACKAGE + ".model";//Model所在包
    public static final String MAPPER_PACKAGE = BASE_PACKAGE + ".dao";//Mapper所在包
    public static final String SERVICE_PACKAGE = BASE_PACKAGE + ".service";//Service所在包
    public static final String SERVICE_IMPL_PACKAGE = SERVICE_PACKAGE + ".impl";//ServiceImpl所在包
    public static final String CONTROLLER_PACKAGE = BASE_PACKAGE + ".controller";//Controller所在包

    public static final String MAPPER_INTERFACE_REFERENCE = BASE_PACKAGE + ".core.Mapper";//Mapper插件基础接口的完全限定名
}

12.代码生成核心业务Result

package com.louis.mango.core;

import com.alibaba.fastjson.JSON;

/**
 * 统一API响应结果封装
 */
public class Result {
    private int code;
    private String message;
    private Object data;

    public Result() {
        super();
    }

    public Result setCode(ResultCode resultCode) {
        this.code = resultCode.code;
        return this;
    }

    public Result(int code, String message) {
        super();
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public Result setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Result setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return data;
    }

    public Result setData(Object data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}

13.代码生成核心业务ResultCode

package com.louis.mango.core;

/**
 * 响应码枚举,参考HTTP状态码的语义
 */
public enum ResultCode {
    SUCCESS(200),//成功
    FAIL(400),//失败
    UNAUTHORIZED(401),//未认证(签名错误)
    NOT_FOUND(404),//接口不存在
    INTERNAL_SERVER_ERROR(500);//服务器内部错误

    public int code;

    ResultCode(int code) {
        this.code = code;
    }
}

14.代码生成核心业务ResultGenerator

package com.louis.mango.core;

/**
 * 响应结果生成工具
 */
public class ResultGenerator {
    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

    public static Result genSuccessResult() {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE);
    }

    public static Result genSuccessResult(Object data) {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE)
                .setData(data);
    }

    public static Result genFailResult(String message) {
        return new Result()
                .setCode(ResultCode.FAIL)
                .setMessage(message);
    }
}

15.代码生成核心业务Service

package com.louis.mango.core;

import org.apache.ibatis.exceptions.TooManyResultsException;
import tk.mybatis.mapper.entity.Condition;

import java.util.List;

/**
 * Service 层 基础接口,其他Service 接口 请继承该接口
 */
public interface Service {
    void save(T model);//持久化
    void save(List models);//批量持久化
    void deleteById(Long id);//通过主鍵刪除
    void deleteByIds(String ids);//批量刪除 eg:ids -> “1,2,3,4”
    void update(T model);//更新
    T findById(Long id);//通过ID查找
    T findBy(String fieldName, Object value) throws TooManyResultsException; //通过Model中某个成员变量名称(非数据表中column的名称)查找,value需符合unique约束
    List findByIds(String ids);//通过多个ID查找//eg:ids -> “1,2,3,4”
    List findByCondition(Condition condition);//根据条件查找
    List findAll();//获取所有
}

16.代码生成核心业务ServiceException

package com.louis.mango.core;

/**
 * 服务(业务)异常如“ 账号或密码错误 ”,该异常只做INFO级别的日志记录 @see WebMvcConfigurer
 */
public class ServiceException extends RuntimeException {
    public ServiceException() {
    }

    public ServiceException(String message) {
        super(message);
    }

    public ServiceException(String message, Throwable cause) {
        super(message, cause);
    }
}

生成代码修改执行CodeGenerator

2021-03-09_113524.png

至此代码生成成功

启动项目MangoApplication

2021-03-09_113759.png

项目启动成功

查看接口http://localhost:8001/swagger-ui.html#/

2021-03-09_114053.png

代码生成整合完毕。

你可能感兴趣的:(spring boot整合MySQL数据库以及代码生成器)