spring boot整合MySQL數(shù)據(jù)庫以及代碼生成器

spring boot整合MySQL數(shù)據(jù)庫以及代碼生成器

項目結(jié)構(gòu)

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

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://IP:PORT/數(shù)據(jù)庫名?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
spring.datasource.username=數(shù)據(jù)庫用戶名
spring.datasource.password=數(shù)據(jù)庫密碼

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

spring.devtools.restart.additional-paths=src/main/java
  • pom表單
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.louis</groupId>
    <artifactId>mango</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mango</name>
    <description>Demo project for Spring Boot</description>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        
        <!-- 集成swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>
        <!-- 集成swagger -->
        <!-- 集成mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>
        <!-- 集成mybatis -->
        <!-- 集成mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!-- 集成mysql -->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            </dependency>
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            </dependency>
        <!--阿里 FastJson依賴-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.39</version>
        </dependency>
        
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>RELEASE</version>
        </dependency>
        
        <!-- 熱部署模塊 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional> <!-- 這個需要為 true 熱部署才有效 -->
        </dependency>
    </dependencies>

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

</project>
  • 數(shù)據(jù)庫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 '數(shù)據(jù)值',
  `label` varchar(100) NOT NULL COMMENT '標(biāo)簽名',
  `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 '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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='系統(tǒng)配置表';

/*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 '機(jī)構(gòu)名稱',
  `parent_id` bigint(20) DEFAULT NULL COMMENT '上級機(jī)構(gòu)ID,一級機(jī)構(gòu)為0',
  `order_num` int(11) DEFAULT NULL COMMENT '排序',
  `create_by` varchar(50) DEFAULT NULL COMMENT '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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='機(jī)構(gòu)管理';

/*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,'輕塵集團(tuán)',NULL,0,'admin','2018-09-23 19:35:22',NULL,NULL,0),(2,'牧塵集團(tuán)',NULL,1,'admin','2018-09-23 19:35:55',NULL,NULL,0),(3,'三國集團(tuán)',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,'技術(shù)部',5,0,'admin','2018-09-23 19:38:00',NULL,NULL,0),(8,'技術(shù)部',4,0,'admin','2018-09-23 19:38:10',NULL,NULL,0),(9,'技術(shù)部',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 '數(shù)據(jù)值',
  `label` varchar(100) NOT NULL COMMENT '標(biāo)簽名',
  `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 '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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 '請求參數(shù)',
  `time` bigint(20) NOT NULL COMMENT '執(zhí)行時長(毫秒)',
  `ip` varchar(64) DEFAULT NULL COMMENT 'IP地址',
  `create_by` varchar(50) DEFAULT NULL COMMENT '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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='系統(tǒng)操作日志';

/*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 '登錄狀態(tài)(online:在線,登錄初始狀態(tài)待错,方便統(tǒng)計在線人數(shù)荚虚;login:退出登錄后將online置為login统诺;logout:退出登錄)',
  `ip` varchar(64) DEFAULT NULL COMMENT 'IP地址',
  `create_by` varchar(50) DEFAULT NULL COMMENT '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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='系統(tǒng)登錄日志';

/*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.嵌套服務(wù)器頁面,使用iframe:前綴+目標(biāo)URL(如SQL監(jiān)控悴务, iframe:/druid/login.html, iframe:前綴會替換成服務(wù)器地址)',
  `perms` varchar(500) DEFAULT NULL COMMENT '授權(quán)(多個用逗號分隔睹限,如:sys:user:add,sys:user:edit)',
  `type` int(11) DEFAULT NULL COMMENT '類型   0:目錄   1:菜單   2:按鈕',
  `icon` varchar(50) DEFAULT NULL COMMENT '菜單圖標(biāo)',
  `order_num` int(11) DEFAULT NULL COMMENT '排序',
  `create_by` varchar(50) DEFAULT NULL COMMENT '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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,'系統(tǒng)管理',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,'機(jī)構(gòu)管理',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,'系統(tǒng)配置',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,'系統(tǒng)監(jiān)控',0,'','',0,'el-icon-info',4,'admin','2018-12-27 10:57:29','admin','2019-01-10 17:31:04',0),(39,'數(shù)據(jù)監(jiān)控',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,'服務(wù)監(jiān)控',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,'服務(wù)治理',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 '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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','項目經(jīng)理','admin','2019-01-19 11:11:11','admin','2019-01-19 11:39:28',0),(3,'dev','開發(fā)人員','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 '角色I(xiàn)D',
  `dept_id` bigint(20) DEFAULT NULL COMMENT '機(jī)構(gòu)ID',
  `create_by` varchar(50) DEFAULT NULL COMMENT '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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='角色機(jī)構(gòu)';

/*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 '角色I(xiàn)D',
  `menu_id` bigint(20) DEFAULT NULL COMMENT '菜單ID',
  `create_by` varchar(50) DEFAULT NULL COMMENT '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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 '手機(jī)號',
  `status` tinyint(4) DEFAULT NULL COMMENT '狀態(tài)  0:禁用   1:正常',
  `dept_id` bigint(20) DEFAULT NULL COMMENT '機(jī)構(gòu)ID',
  `create_by` varchar(50) DEFAULT NULL COMMENT '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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','admin@qq.com','13612345678',1,4,'admin','2018-08-14 11:11:11','admin','2018-08-14 11:11:11',0),(22,'liubei','劉備',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','13889700023',1,7,'admin','2018-09-23 19:43:00','admin','2019-01-10 11:41:13',0),(23,'zhaoyun','趙云',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','13889700023',1,7,'admin','2018-09-23 19:43:44','admin','2018-09-23 19:43:52',0),(24,'zhugeliang','諸葛亮',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','13889700023',7,11,'admin','2018-09-23 19:44:23','admin','2018-09-23 19:44:29',0),(25,'caocao','曹操',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','13889700023',1,8,'admin','2018-09-23 19:45:32','admin','2019-01-10 17:59:14',0),(26,'dianwei','典韋',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','13889700023',1,10,'admin','2018-09-23 19:45:48','admin','2018-09-23 19:45:57',0),(27,'xiahoudun','夏侯惇',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','13889700023',1,8,'admin','2018-09-23 19:46:09','admin','2018-09-23 19:46:17',0),(28,'xunyu','荀彧',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','13889700023',1,10,'admin','2018-09-23 19:46:38','admin','2018-11-04 15:33:17',0),(29,'sunquan','孫權(quán)',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','13889700023',1,10,'admin','2018-09-23 19:46:54','admin','2018-09-23 19:47:03',0),(30,'zhouyu','周瑜',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','13889700023',1,11,'admin','2018-09-23 19:47:28','admin','2018-09-23 19:48:04',0),(31,'luxun','陸遜',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','13889700023',1,11,'admin','2018-09-23 19:47:44','admin','2018-09-23 19:47:58',0),(32,'huanggai','黃蓋',NULL,'fd80ebd493a655608dc893a9f897d845','YzcmCZNvbXocrsz9dm8e','test@qq.com','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 '角色I(xiàn)D',
  `create_by` varchar(50) DEFAULT NULL COMMENT '創(chuàng)建人',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間',
  `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.*;

/**
 * 代碼生成器,根據(jù)數(shù)據(jù)表名稱生成對應(yīng)的Model讯檐、Mapper羡疗、Service、Controller簡化開發(fā)裂垦。
 */
public class CodeGenerator {
    //JDBC配置顺囊,請修改為你項目的實際配置
    private static final String JDBC_URL = "jdbc:mysql://localhost:3306/mango";
    private static final String JDBC_USERNAME = "數(shù)據(jù)庫用戶名";
    private static final String JDBC_PASSWORD = "數(shù)據(jù)庫密碼";
    private static final String JDBC_DIVER_CLASS_NAME = "com.mysql.jdbc.Driver";

    private static final String PROJECT_PATH = System.getProperty("user.dir");//項目在硬盤上的基礎(chǔ)路徑
    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實現(xiàn)存放路徑
    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("數(shù)據(jù)庫表名1");
        genCode("數(shù)據(jù)庫表名2","數(shù)據(jù)庫表名3");
    }

    /**
     * 通過數(shù)據(jù)表名稱生成代碼肌索,Model 名稱通過解析數(shù)據(jù)表名稱獲得蕉拢,下劃線轉(zhuǎn)大駝峰的形式。
     * 如輸入表名稱 "t_user_detail" 將生成 TUserDetail诚亚、TUserDetailMapper晕换、TUserDetailService ...
     * @param tableNames 數(shù)據(jù)表名稱...
     */
    public static void genCode(String... tableNames) {
        for (String tableName : tableNames) {
            genCodeByCustomModelName(tableName, null);
        }
    }

    /**
     * 通過數(shù)據(jù)表名稱,和自定義的 Model 名稱生成代碼
     * 如輸入表名稱 "t_user_detail" 和自定義的 Model 名稱 "User" 將生成 User站宗、UserMapper闸准、UserService ...
     * @param tableName 數(shù)據(jù)表名稱
     * @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<String> warnings;
        MyBatisGenerator generator;
        try {
            Configuration config = new Configuration();
            config.addContext(context);
            config.validate();

            boolean overwrite = true;
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            warnings = new ArrayList<String>();
            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<String, Object> 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<String, Object> 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="創(chuàng)建${modelNameLowerCamel}", notes="根據(jù)${modelNameUpperCamel}對象創(chuàng)建")
    @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="根據(jù)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="根據(jù)id來指定更新對象梢灭,并根據(jù)傳過來的${modelNameLowerCamel}信息來更新其詳細(xì)信息")
    @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}詳細(xì)信息", notes="根據(jù)id來獲取${modelNameUpperCamel}詳細(xì)信息")
    @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.代碼生成核心業(yè)務(wù)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接口的實現(xiàn)
 */
@Transactional
public abstract class AbstractService<T> implements Service<T> {

    @Autowired
    protected Mapper<T> mapper;

    private Class<T> modelClass;    // 當(dāng)前泛型真實類型的Class

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

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

    public void save(List<T> 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<T> findByIds(String ids) {
        return mapper.selectByIds(ids);
    }

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

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

10.代碼生成核心業(yè)務(wù)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<T>
        extends
        BaseMapper<T>,
        ConditionMapper<T>,
        IdsMapper<T>,
        InsertListMapper<T> {
}

11.代碼生成核心業(yè)務(wù)ProjectConstant

package com.louis.mango.core;

/**
 * 項目常量
 */
public final class ProjectConstant {
    public static final String BASE_PACKAGE = "com.louis.mango";//項目基礎(chǔ)包名稱敏释,根據(jù)自己公司的項目修改

    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插件基礎(chǔ)接口的完全限定名
}

12.代碼生成核心業(yè)務(wù)Result

package com.louis.mango.core;

import com.alibaba.fastjson.JSON;

/**
 * 統(tǒng)一API響應(yīng)結(jié)果封裝
 */
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.代碼生成核心業(yè)務(wù)ResultCode

package com.louis.mango.core;

/**
 * 響應(yīng)碼枚舉库快,參考HTTP狀態(tài)碼的語義
 */
public enum ResultCode {
    SUCCESS(200),//成功
    FAIL(400),//失敗
    UNAUTHORIZED(401),//未認(rèn)證(簽名錯誤)
    NOT_FOUND(404),//接口不存在
    INTERNAL_SERVER_ERROR(500);//服務(wù)器內(nèi)部錯誤

    public int code;

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

14.代碼生成核心業(yè)務(wù)ResultGenerator

package com.louis.mango.core;

/**
 * 響應(yīng)結(jié)果生成工具
 */
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.代碼生成核心業(yè)務(wù)Service

package com.louis.mango.core;

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

import java.util.List;

/**
 * Service 層 基礎(chǔ)接口,其他Service 接口 請繼承該接口
 */
public interface Service<T> {
    void save(T model);//持久化
    void save(List<T> 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中某個成員變量名稱(非數(shù)據(jù)表中column的名稱)查找,value需符合unique約束
    List<T> findByIds(String ids);//通過多個ID查找//eg:ids -> “1,2,3,4”
    List<T> findByCondition(Condition condition);//根據(jù)條件查找
    List<T> findAll();//獲取所有
}

16.代碼生成核心業(yè)務(wù)ServiceException

package com.louis.mango.core;

/**
 * 服務(wù)(業(yè)務(wù))異常如“ 賬號或密碼錯誤 ”钥顽,該異常只做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);
    }
}

生成代碼修改執(zhí)行CodeGenerator

2021-03-09_113524.png

至此代碼生成成功

啟動項目MangoApplication

2021-03-09_113759.png

項目啟動成功

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

2021-03-09_114053.png

代碼生成整合完畢义屏。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子闽铐,更是在濱河造成了極大的恐慌蝶怔,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,561評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件兄墅,死亡現(xiàn)場離奇詭異踢星,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)察迟,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,218評論 3 385
  • 文/潘曉璐 我一進(jìn)店門斩狱,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人扎瓶,你說我怎么就攤上這事所踊。” “怎么了概荷?”我有些...
    開封第一講書人閱讀 157,162評論 0 348
  • 文/不壞的土叔 我叫張陵秕岛,是天一觀的道長。 經(jīng)常有香客問我误证,道長继薛,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,470評論 1 283
  • 正文 為了忘掉前任愈捅,我火速辦了婚禮遏考,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘蓝谨。我一直安慰自己灌具,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 65,550評論 6 385
  • 文/花漫 我一把揭開白布譬巫。 她就那樣靜靜地躺著咖楣,像睡著了一般。 火紅的嫁衣襯著肌膚如雪芦昔。 梳的紋絲不亂的頭發(fā)上诱贿,一...
    開封第一講書人閱讀 49,806評論 1 290
  • 那天,我揣著相機(jī)與錄音咕缎,去河邊找鬼珠十。 笑死,一個胖子當(dāng)著我的面吹牛凭豪,可吹牛的內(nèi)容都是我干的焙蹭。 我是一名探鬼主播,決...
    沈念sama閱讀 38,951評論 3 407
  • 文/蒼蘭香墨 我猛地睜開眼墅诡,長吁一口氣:“原來是場噩夢啊……” “哼壳嚎!你這毒婦竟也來了桐智?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,712評論 0 266
  • 序言:老撾萬榮一對情侶失蹤烟馅,失蹤者是張志新(化名)和其女友劉穎说庭,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體郑趁,經(jīng)...
    沈念sama閱讀 44,166評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡刊驴,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,510評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了寡润。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片捆憎。...
    茶點故事閱讀 38,643評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖梭纹,靈堂內(nèi)的尸體忽然破棺而出躲惰,到底是詐尸還是另有隱情,我是刑警寧澤变抽,帶...
    沈念sama閱讀 34,306評論 4 330
  • 正文 年R本政府宣布础拨,位于F島的核電站,受9級特大地震影響绍载,放射性物質(zhì)發(fā)生泄漏诡宗。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,930評論 3 313
  • 文/蒙蒙 一击儡、第九天 我趴在偏房一處隱蔽的房頂上張望塔沃。 院中可真熱鬧,春花似錦阳谍、人聲如沸蛀柴。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,745評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽名扛。三九已至谅年,卻和暖如春茧痒,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背融蹂。 一陣腳步聲響...
    開封第一講書人閱讀 31,983評論 1 266
  • 我被黑心中介騙來泰國打工旺订, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人超燃。 一個月前我還...
    沈念sama閱讀 46,351評論 2 360
  • 正文 我出身青樓区拳,卻偏偏與公主長得像,于是被迫代替她去往敵國和親意乓。 傳聞我的和親對象是個殘疾皇子樱调,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,509評論 2 348

推薦閱讀更多精彩內(nèi)容