├── src ├── main │ ├── resources │ │ ├── application.properties │ │ ├── static │ │ │ ├── fade-logo.png │ │ │ ├── fade_favicon.ico │ │ │ └── index.html │ │ ├── mapper.java.vm │ │ ├── logicServiceItf.java.vm │ │ ├── entity.vm │ │ ├── logicService.java.vm │ │ └── mapper.xml.vm │ └── java │ │ └── com │ │ └── fade │ │ └── mybatis │ │ ├── MybatisGeneratorHelperApplication.java │ │ ├── utils │ │ ├── ConstansValue.java │ │ ├── CloseableUtils.java │ │ ├── CollectionUtil.java │ │ └── StringUtils.java │ │ ├── vo │ │ ├── ResultVo.java │ │ ├── GeneratorVo.java │ │ └── DBConfigVo.java │ │ ├── controller │ │ ├── GlobalExceptionHandler.java │ │ └── HomeController.java │ │ ├── enums │ │ ├── EncodeType.java │ │ ├── DbType.java │ │ ├── TemplateType.java │ │ └── NamingStrategyType.java │ │ ├── model │ │ ├── Template.java │ │ ├── TableInfo.java │ │ └── TableField.java │ │ ├── service │ │ ├── in │ │ │ ├── VelocityTemplate.java │ │ │ ├── LocalDBHelper.java │ │ │ └── DbServiceHelper.java │ │ └── out │ │ │ └── DataSourceService.java │ │ ├── config │ │ ├── TemplateConfig.java │ │ ├── DataSourceConfig.java │ │ ├── builder │ │ │ └── DataSourceConfigBuilder.java │ │ └── GeneratorConfig.java │ │ └── dto │ │ └── PageDto.java └── test │ └── java │ └── com │ └── fade │ └── mybatis │ └── MybatisGeneratorHelperApplicationTests.java ├── wiki ├── file.png ├── index.png ├── xml.png ├── column.png ├── entity.png ├── service.png ├── tables.png ├── connection.png └── generater.png ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .gitignore ├── readme.md └── pom.xml /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /wiki/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/wiki/file.png -------------------------------------------------------------------------------- /wiki/index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/wiki/index.png -------------------------------------------------------------------------------- /wiki/xml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/wiki/xml.png -------------------------------------------------------------------------------- /wiki/column.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/wiki/column.png -------------------------------------------------------------------------------- /wiki/entity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/wiki/entity.png -------------------------------------------------------------------------------- /wiki/service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/wiki/service.png -------------------------------------------------------------------------------- /wiki/tables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/wiki/tables.png -------------------------------------------------------------------------------- /wiki/connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/wiki/connection.png -------------------------------------------------------------------------------- /wiki/generater.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/wiki/generater.png -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/static/fade-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/src/main/resources/static/fade-logo.png -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip 2 | -------------------------------------------------------------------------------- /src/main/resources/static/fade_favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixinyiyu/mybatis-fade-helper/HEAD/src/main/resources/static/fade_favicon.ico -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | mvnw 18 | mvnw.cmd 19 | 20 | ### NetBeans ### 21 | nbproject/private/ 22 | build/ 23 | nbbuild/ 24 | dist/ 25 | nbdist/ 26 | .nb-gradle/ 27 | /DBConfig.db 28 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/MybatisGeneratorHelperApplication.java: -------------------------------------------------------------------------------- 1 | package com.fade.mybatis; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MybatisGeneratorHelperApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MybatisGeneratorHelperApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/utils/ConstansValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.utils;/** 6 | * Created by qingquanzhong on 2016/12/19. 7 | */ 8 | 9 | /** 10 | * Description: 常量
11 | * 12 | * @author qingquanzhong 13 | * @version 1.0 14 | * @date: 2016-12-18 19:10:09 15 | * @since JDK 1.8 16 | */ 17 | public class ConstansValue { 18 | public static final char UNDERLINE = '_'; 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/com/fade/mybatis/MybatisGeneratorHelperApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.fade.mybatis; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class MybatisGeneratorHelperApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/utils/CloseableUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.utils;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | /** 10 | * Description: {一句话描述类是干什么的}
11 | * 12 | * @author qingquanzhong 13 | * @version 1.0 14 | * @date: 2016-12-18 15 | * @since JDK 1.8 16 | */ 17 | public final class CloseableUtils { 18 | private CloseableUtils(){ 19 | } 20 | 21 | public static void closeQuietly(AutoCloseable close) { 22 | try { 23 | closeQuietly(close, false); 24 | } catch (Exception e) { 25 | e.printStackTrace(); 26 | } 27 | } 28 | 29 | /** 关闭资源,throwEx 为true则抛出异常 */ 30 | public static void closeQuietly(AutoCloseable close, boolean throwEx) throws Exception { 31 | if (null != close) { 32 | try { 33 | close.close(); 34 | } catch (Exception e) { 35 | if (throwEx) 36 | throw e; 37 | } finally { 38 | close = null; 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Mybatis代码自动生成工具 2 | 3 | ## 相关技术 4 | 5 | * Java8 6 | * SpringBoot 7 | * Velocity 8 | * PageHelper(分页查询使用V:5.0.2) 9 | * Vue.js+Element-UI 10 | 11 | ## 项目截图 12 | 13 | 首页(数据库连接列表): 14 | ![index](wiki/index.png) 15 | 16 | 指定连接下表: 17 | ![table](wiki/tables.png) 18 | 19 | 指定表下栏目: 20 | ![column](wiki/column.png) 21 | 22 | 新建数据库连接: 23 | ![connection](wiki/connection.png) 24 | 25 | 代码生成参数: 26 | ![generater](wiki/generater.png) 27 | 28 | 生成文件: 29 | ![file](wiki/file.png) 30 | 31 | 实体代码: 32 | ![entity](wiki/entity.png) 33 | 34 | Mybatis配置: 35 | ![xml](wiki/xml.png) 36 | 37 | 逻辑服务 38 | ![service](wiki/service.png) 39 | 40 | ## 运行 41 | 42 | mvn install -Dmaven.test.skip=true 43 | 44 | java -jar boot.jar -jar mybatis-generator-helper-0.0.1-SNAPSHOT.jar --server.port=9090 45 | 46 | 1) 首先新建数据库连接(连接可以选择保存本地) 47 | 2) 指定初始化加载某连接 48 | 3) 填写自动生成所需配置 49 | 4) 执行代码生成即可 50 | 51 | ## 开发计划 52 | 53 | * version 1.1 [planning] 54 | * (1) 模版更灵活化 55 | * (2) 生成更多通用代码 56 | 57 | * version 1.0 [finished] 58 | * ~~(1) 项目搭建~~ 59 | * ~~(2) 基于模版的项目生成~~ 60 | * ~~(3) 可配置化 61 | * ~~(4) 前端代码 62 | 63 | 64 | ## 相关信息 65 | 66 | 此项目平时学习开发过程中用来快速开发,节省约会时间。 67 | 有任何问题可以联系[qingquanzhong@126.com] -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/utils/CollectionUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.utils;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | import java.util.Collection; 10 | import java.util.Map; 11 | 12 | /** 13 | * Description: 集合工具
14 | * 15 | * @author qingquanzhong 16 | * @version 1.0 17 | * @date: 2016-12-18 13:44:11 18 | * @since JDK 1.8 19 | */ 20 | public final class CollectionUtil { 21 | 22 | private CollectionUtil(){ 23 | 24 | } 25 | 26 | public static boolean isEmpty(Collection col) { 27 | return null == col || col.isEmpty(); 28 | } 29 | 30 | public static boolean isNotEmpty(Collection col) { 31 | return !isEmpty(col); 32 | } 33 | 34 | public static boolean isEmpty(Map map) { 35 | return null == map || map.isEmpty(); 36 | } 37 | 38 | public static boolean isNotEmpty(Map map) { 39 | return !isEmpty(map); 40 | } 41 | 42 | /**初始化map的容量、减少扩容影响*/ 43 | public static int capacitySize(int expectedSize) { 44 | if (expectedSize < 3) return expectedSize + 1; 45 | return (int) ((float) expectedSize / 0.75F + 1.0F); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/resources/mapper.java.vm: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package ${package.Mapper}; 5 | 6 | import java.util.List; 7 | 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | import ${package.Entity}.${entityName}; 11 | 12 | /** 13 | * Description: ${table.comment} Dao
14 | * 15 | * @author ${author} 16 | * @version 1.0 17 | * @date: ${date} 18 | * @since JDK 1.8 19 | */ 20 | public interface ${table.entityName}Mapper { 21 | 22 | /**可选插入返回主键*/ 23 | ${table.keyField.propertyType} insertSelective(${entityName} entity); 24 | 25 | /**批量插入返回影响记录数*/ 26 | int insertRecords(@Param("records") List<${entityName}> records); 27 | 28 | ${entityName} queryLimitOne(${entityName} entity); 29 | 30 | /**批量主键查询*/ 31 | List<${entityName}> queryBy${table.keyField.capitalPropertyName}s(@Param("keys") List<${table.keyField.propertyType}> ${table.keyField.propertyName}s); 32 | 33 | /**条件查询*/ 34 | List<${entityName}> queryByCond(${entityName} entity); 35 | 36 | /**主键查询*/ 37 | ${entityName} queryBy${table.keyField.capitalPropertyName} (@Param("${table.keyField.propertyName}") ${table.keyField.propertyType} ${table.keyField.propertyName}); 38 | 39 | /**主键更新*/ 40 | int update${table.entityName}By${table.keyField.capitalPropertyName} (${entityName} entity); 41 | 42 | /**主键删除*/ 43 | int delete${table.entityName}By${table.keyField.capitalPropertyName} (@Param("${table.keyField.propertyName}") ${table.keyField.propertyType} ${table.keyField.propertyName}); 44 | 45 | } -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.utils; 6 | 7 | /** 8 | * Created by Administrator on 2016/12/18. 9 | */ 10 | 11 | /** 12 | * Description: 字符串工具类
13 | * 14 | * @author qingquanzhong 15 | * @version 1.0 16 | * @date: 2016-12-18 06:01:11 17 | * @since JDK 1.8 18 | */ 19 | public final class StringUtils { 20 | 21 | private StringUtils(){ 22 | 23 | } 24 | 25 | public static String concat (String base, String target, String with){ 26 | if (isBlank(base)) return with + target; 27 | if (!base.endsWith(with)) base =base + with; 28 | return base + target; 29 | } 30 | 31 | /** 32 | * 判断所给字符串是否空或空串. 33 | *
34 |      * isBlank(null) = true
35 |      * isBlank("") = true
36 |      * isBlank("sss ") = false
37 |      * 
38 | * @author qingquanzhong 39 | * @param str 目标字符串 40 | * @return 是否为空 41 | */ 42 | public static boolean isBlank(CharSequence str) { 43 | int len; 44 | if (str == null || (len = str.length()) == 0) { 45 | return true; 46 | } 47 | for (int i = 0; i < len; i++) { 48 | if (!Character.isWhitespace(str.charAt(i))) { 49 | return false; 50 | } 51 | } 52 | return true; 53 | } 54 | 55 | public static boolean isNotBlank(CharSequence str) { 56 | return !isBlank(str); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/resources/logicServiceItf.java.vm: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package ${package.LogicServiceItf}; 5 | 6 | import java.util.List; 7 | import ${package.Entity}.${entityName}; 8 | 9 | /** 10 | * Description: ${table.comment} 逻辑服务类
11 | * 12 | * @author ${author} 13 | * @version 1.0 14 | * @date: ${date} 15 | * @since JDK 1.8 16 | */ 17 | public interface I${table.entityName}LogicService { 18 | 19 | /**可选插入返回主键*/ 20 | ${table.keyField.propertyType} insert${table.entityName}(${entityName} entity); 21 | 22 | /**批量插入*/ 23 | void insert${table.entityName}s(List<${entityName}> records); 24 | 25 | /**条件查询一条记录*/ 26 | ${entityName} query${table.entityName}LimitOne(${entityName} entity); 27 | 28 | /**条件查询*/ 29 | List<${entityName}> queryByCond(${entityName} entity); 30 | 31 | /**分页查询*/ 32 | PageDto<${entityName}> pageQueryByCond(${entityName} entity, int pageNum, int pageSize); 33 | 34 | /**主键查询*/ 35 | ${entityName} query${table.entityName}By${table.keyField.capitalPropertyName} (${table.keyField.propertyType} ${table.keyField.propertyName}); 36 | 37 | /**主键批量查询*/ 38 | List<${entityName}> query${table.entityName}By${table.keyField.capitalPropertyName}s (List<${table.keyField.propertyType}> ${table.keyField.propertyName}s); 39 | 40 | /**主键更新*/ 41 | boolean update${table.entityName}By${table.keyField.capitalPropertyName} (${entityName} entity); 42 | 43 | /**主键删除*/ 44 | boolean delete${table.entityName}By${table.keyField.capitalPropertyName} (${table.keyField.propertyType} ${table.keyField.propertyName}); 45 | 46 | } -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/vo/ResultVo.java: -------------------------------------------------------------------------------- 1 | package com.fade.mybatis.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.fade.mybatis.utils.StringUtils; 6 | 7 | /** 8 | * Description: 统一对外模型
9 | * 10 | * @author qingquanzhong 11 | * @version 1.0 12 | * @date: 2016-12-20 13:01:14 13 | * @since JDK 1.8 14 | */ 15 | public class ResultVo implements Serializable { 16 | 17 | private static final long serialVersionUID = 9130894805115698656L; 18 | 19 | /**响应码(0:成功,其他失败)*/ 20 | private Integer code; 21 | 22 | /**结果*/ 23 | private T data; 24 | 25 | /**提示信息*/ 26 | private String message; 27 | 28 | public Integer getCode() { 29 | return code; 30 | } 31 | 32 | public ResultVo setCode(Integer code) { 33 | this.code = code; 34 | return this; 35 | } 36 | 37 | public Object getData() { 38 | return data; 39 | } 40 | 41 | public ResultVo setData(T data) { 42 | this.data = data; 43 | return this; 44 | } 45 | 46 | public String getMessage() { 47 | return message; 48 | } 49 | 50 | public ResultVo setMessage(String message) { 51 | this.message = message; 52 | return this; 53 | } 54 | 55 | public ResultVo setSuccessValue(T data) { 56 | this.message = "成功"; 57 | this.code = 0; 58 | this.data = data; 59 | return this; 60 | } 61 | 62 | public ResultVo setFaildMessage(String message) { 63 | this.code = -1; 64 | this.message = StringUtils.isBlank(message) ? "操作失败" : message; 65 | return this; 66 | } 67 | 68 | public boolean success() { 69 | return null == this.code ? false : 0 == this.code.intValue(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/controller/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.fade.mybatis.controller; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.web.HttpMediaTypeNotSupportedException; 10 | import org.springframework.web.HttpRequestMethodNotSupportedException; 11 | import org.springframework.web.bind.annotation.ControllerAdvice; 12 | import org.springframework.web.bind.annotation.ExceptionHandler; 13 | import org.springframework.web.bind.annotation.ResponseStatus; 14 | 15 | import com.fade.mybatis.vo.ResultVo; 16 | 17 | /** 18 | * @author qingquanzhong 全局异常 19 | */ 20 | @ControllerAdvice 21 | public class GlobalExceptionHandler { 22 | 23 | private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); 24 | 25 | /** 26 | * 405 - Method Not Allowed 27 | */ 28 | @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) 29 | @ExceptionHandler(HttpRequestMethodNotSupportedException.class) 30 | public Object handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { 31 | logger.error("不支持当前请求方法", e); 32 | return new ResultVo<>().setFaildMessage("不支持当前请求方法"); 33 | } 34 | 35 | /** 36 | * 415 - Unsupported Media Type 37 | */ 38 | @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE) 39 | @ExceptionHandler(HttpMediaTypeNotSupportedException.class) 40 | public Object handleHttpMediaTypeNotSupportedException(Exception e) { 41 | logger.error("不支持当前媒体类型", e); 42 | return new ResultVo<>().setFaildMessage("content_type_not_supported"); 43 | } 44 | 45 | /** 46 | * 500 - Internal Server Error 47 | */ 48 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) 49 | @ExceptionHandler(Exception.class) 50 | public Object handleException(Exception e) { 51 | logger.error("通用异常", e); 52 | return new ResultVo<>().setFaildMessage("内部服务器:" + e.getMessage()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/enums/EncodeType.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.enums;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | import com.fade.mybatis.utils.CollectionUtil; 10 | import com.fade.mybatis.utils.StringUtils; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | /** 16 | * Description: 编码
17 | * 18 | * @author qingquanzhong 19 | * @version 1.0 20 | * @date: 2016-12-18 13:49:01 21 | * @since JDK 1.8 22 | */ 23 | public enum EncodeType { 24 | 25 | UTF8{ 26 | @Override 27 | public String getValue() { 28 | 29 | return "UTF-8"; 30 | } 31 | 32 | @Override 33 | public String getDesc() { 34 | 35 | return "UTF-8"; 36 | } 37 | }, 38 | GBK{ 39 | @Override 40 | public String getValue() { 41 | 42 | return "gbk"; 43 | } 44 | 45 | @Override 46 | public String getDesc() { 47 | 48 | return "GBK 中文"; 49 | } 50 | }, 51 | GB2312{ 52 | @Override 53 | public String getValue() { 54 | 55 | return "gb2312"; 56 | } 57 | 58 | @Override 59 | public String getDesc() { 60 | 61 | return "GBK2312"; 62 | } 63 | }; 64 | 65 | public abstract String getValue(); 66 | 67 | public abstract String getDesc(); 68 | 69 | private static final Map map; 70 | 71 | static { 72 | map = new HashMap<>(CollectionUtil.capacitySize(values().length)); 73 | for (EncodeType type : values()) { 74 | map.put(type.getValue(), type); 75 | } 76 | } 77 | 78 | /**根据key获取枚举,未匹配到则返回空*/ 79 | public static EncodeType get(String value) { 80 | if (StringUtils.isBlank(value)) return null; 81 | return map.get(value); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/resources/entity.vm: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2017

3 | *

Company: fade

4 | */ 5 | package ${package.Entity}; 6 | 7 | import java.io.Serializable; 8 | #if(${table.hasDate}) 9 | import java.util.Date; 10 | #end 11 | 12 | /** 13 | * Description: ${table.comment}
14 | * 15 | * @author ${author} 16 | * @version 1.0 17 | * @date: ${date} 18 | * @since JDK 1.8 19 | */ 20 | public class ${entityName} implements Serializable { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | ## 设置属性 25 | #foreach($field in ${table.fields}) 26 | /**${field.comment}*/ 27 | private ${field.propertyType} ${field.propertyName}; 28 | 29 | #end 30 | ## set/get方法 31 | #foreach($field in ${table.fields}) 32 | ## 针对is开头Boolean属性处理 33 | #if(${field.propertyType.equals("Boolean")}) 34 | #set($sName = ${field.booleanSetPropertyName}) 35 | #set($gName = ${field.booleanPropertyName}) 36 | #else 37 | #set($sName = ${field.capitalSetPropertyName}) 38 | #set($gName = ${field.capitalGetPropertyName}) 39 | #end 40 | 41 | /**{@linkplain #${field.propertyName}}*/ 42 | #if(${simpleBuilderModel}) 43 | public ${entityName} ${sName}(${field.propertyType} ${field.propertyName}) { 44 | this.${field.propertyName} = ${field.propertyName}; 45 | return this; 46 | } 47 | #else 48 | public void ${sName}(${field.propertyType} ${field.propertyName}) { 49 | this.${field.propertyName} = ${field.propertyName}; 50 | } 51 | #end 52 | 53 | /**{@linkplain #${field.propertyName}}*/ 54 | public ${field.propertyType} ${gName}() { 55 | return this.${field.propertyName}; 56 | } 57 | #end 58 | 59 | ## toString方法 60 | @Override 61 | public String toString() { 62 | final StringBuilder sb = new StringBuilder("${entityName} ["); 63 | #foreach($field in ${table.fields}) 64 | #if($velocityCount == 1) 65 | sb.append("${field.propertyName}="); 66 | #else 67 | sb.append(",${field.propertyName}="); 68 | #end 69 | sb.append(${field.propertyName}).append(","); 70 | #end 71 | sb.append(']'); 72 | return sb.toString(); 73 | } 74 | 75 | } -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/model/Template.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.model;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | import com.fade.mybatis.enums.TemplateType; 10 | 11 | import java.io.Serializable; 12 | 13 | /** 14 | * Description: 模版模型
15 | * 16 | * @author qingquanzhong 17 | * @version 1.0 18 | * @date: 2016-12-18 18:02:31 19 | * @since JDK 1.8 20 | */ 21 | public class Template implements Serializable{ 22 | 23 | private static final long serialVersionUID = 6879021516337954675L; 24 | 25 | /**模版标识*/ 26 | private Integer id; 27 | 28 | /**模版名称*/ 29 | private String name; 30 | 31 | /**模版描述*/ 32 | private String desc; 33 | 34 | /**模版所在路径*/ 35 | private String path; 36 | 37 | /**类型*/ 38 | private TemplateType type; 39 | 40 | public TemplateType getType() { 41 | return type; 42 | } 43 | 44 | public Template setType(TemplateType type) { 45 | this.type = type; 46 | return this; 47 | } 48 | 49 | public String getName() { 50 | return name; 51 | } 52 | 53 | public Template setName(String name) { 54 | this.name = name; 55 | return this; 56 | } 57 | 58 | public String getDesc() { 59 | return desc; 60 | } 61 | 62 | public Template setDesc(String desc) { 63 | this.desc = desc; 64 | return this; 65 | } 66 | 67 | public String getPath() { 68 | return path; 69 | } 70 | 71 | public Template setPath(String path) { 72 | this.path = path; 73 | return this; 74 | } 75 | 76 | public Integer getId() { 77 | return id; 78 | } 79 | 80 | public void setId(Integer id) { 81 | this.id = id; 82 | } 83 | 84 | @Override 85 | public String toString() { 86 | final StringBuffer sb = new StringBuffer("Template{"); 87 | sb.append("id=").append(id); 88 | sb.append(", name='").append(name).append('\''); 89 | sb.append(", desc='").append(desc).append('\''); 90 | sb.append(", path='").append(path).append('\''); 91 | sb.append(", type='").append(type).append('\''); 92 | sb.append('}'); 93 | return sb.toString(); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/service/in/VelocityTemplate.java: -------------------------------------------------------------------------------- 1 | package com.fade.mybatis.service.in; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.OutputStreamWriter; 7 | 8 | import org.apache.velocity.Template; 9 | import org.apache.velocity.VelocityContext; 10 | import org.apache.velocity.app.VelocityEngine; 11 | import org.apache.velocity.runtime.RuntimeConstants; 12 | import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.stereotype.Service; 16 | 17 | @Service 18 | public class VelocityTemplate { 19 | 20 | private static final Logger logger = LoggerFactory.getLogger(VelocityTemplate.class); 21 | 22 | private VelocityEngine vEngine = null; 23 | 24 | private VelocityEngine getVelocityEngine() { 25 | if (null != vEngine) 26 | return vEngine; 27 | logger.info("初始化Velocity引擎........."); 28 | // 设置Velocity引擎 29 | vEngine = new VelocityEngine(); 30 | // 引擎配置 31 | vEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); 32 | //解决中文乱码问题 33 | vEngine.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8"); 34 | vEngine.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8"); 35 | vEngine.setProperty(RuntimeConstants.ENCODING_DEFAULT, "UTF-8"); 36 | vEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); 37 | // 初始化引擎 38 | vEngine.init(); 39 | return vEngine; 40 | } 41 | 42 | /** 43 | * 根据模板生成文件到指定目录 44 | * @param vContext Velocity上下文 45 | * @param vmTemplatePath 模版路径 46 | * @param outputPath 目标文件目录 47 | */ 48 | public void mergeVm2File(VelocityContext vContext, String vmTemplatePath, String outputPath) { 49 | VelocityEngine engine = getVelocityEngine(); 50 | // 设置模板 51 | Template t = engine.getTemplate(vmTemplatePath); 52 | try { 53 | /**创建父目录*/ 54 | File outputFile = new File(outputPath); 55 | if (!outputFile.getParentFile().exists()) outputFile.getParentFile().mkdirs(); 56 | FileOutputStream fos = new FileOutputStream(outputPath); 57 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")); 58 | t.merge(vContext, writer); 59 | writer.close(); 60 | logger.info("成功生成 {}文件", outputFile.getName()); 61 | } catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/config/TemplateConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.config;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | import com.fade.mybatis.enums.TemplateType; 10 | import com.fade.mybatis.model.Template; 11 | 12 | /** 13 | * Description: 基于Velocity模版配置
14 | * 15 | * @author qingquanzhong 16 | * @version 1.0 17 | * @date: 2016-12-18 18:01:23 18 | * @since JDK 1.8 19 | */ 20 | public class TemplateConfig { 21 | 22 | /**实体*/ 23 | private Template entity; 24 | 25 | /**xml*/ 26 | private Template mapper; 27 | 28 | /**dao接口*/ 29 | private Template dao; 30 | 31 | /**基础service*/ 32 | private Template service; 33 | 34 | private Template serviceItf; 35 | 36 | public Template getEntity() { 37 | return entity; 38 | } 39 | 40 | public TemplateConfig setEntity(Template entity) { 41 | this.entity = entity; 42 | return this; 43 | } 44 | 45 | public Template getMapper() { 46 | return mapper; 47 | } 48 | 49 | public TemplateConfig setMapper(Template mapper) { 50 | this.mapper = mapper; 51 | return this; 52 | } 53 | 54 | public Template getDao() { 55 | return dao; 56 | } 57 | 58 | public TemplateConfig setDao(Template dao) { 59 | this.dao = dao; 60 | return this; 61 | } 62 | 63 | public Template getService() { 64 | return service; 65 | } 66 | 67 | public TemplateConfig setService(Template service) { 68 | this.service = service; 69 | return this; 70 | } 71 | 72 | public Template getServiceItf() { 73 | return serviceItf; 74 | } 75 | 76 | public TemplateConfig setServiceItf(Template serviceItf) { 77 | this.serviceItf = serviceItf; 78 | return this; 79 | } 80 | 81 | public static TemplateConfig getDefault() { 82 | TemplateConfig templateConfig = new TemplateConfig(); 83 | templateConfig.setEntity(new Template().setType(TemplateType.entity_java).setPath("entity.vm")) 84 | .setMapper(new Template().setType(TemplateType.mapper_xml).setPath("mapper.xml.vm")) 85 | .setDao(new Template().setType(TemplateType.mapper_java).setPath("mapper.java.vm")) 86 | .setService(new Template().setType(TemplateType.service_java).setPath("logicService.java.vm")) 87 | .setServiceItf(new Template().setType(TemplateType.service_java).setPath("logicServiceItf.java.vm")); 88 | return templateConfig; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example 7 | mybatis-generator-helper 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | mybatis-generator-helper 12 | mybatis generator helper 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.4.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 6.0.5 26 | 1.7 27 | 22.0 28 | 3.0.5 29 | 1.2.36 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-web 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | test 47 | 48 | 49 | mysql 50 | mysql-connector-java 51 | 52 | 53 | org.apache.velocity 54 | velocity 55 | 56 | 57 | com.google.guava 58 | guava 59 | ${guava.version} 60 | 61 | 62 | org.mapdb 63 | mapdb 64 | ${mapdb.version} 65 | 66 | 67 | com.alibaba 68 | fastjson 69 | ${fastjson.version} 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | org.springframework.boot 78 | spring-boot-maven-plugin 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/model/TableInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.model;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | import java.io.Serializable; 10 | import java.util.List; 11 | 12 | import com.fade.mybatis.enums.NamingStrategyType; 13 | import com.google.common.collect.Lists; 14 | 15 | 16 | /** 17 | * Description: 表信息
18 | * 19 | * @author qingquanzhong 20 | * @version 1.0 21 | * @date: 2016-12-18 12:10:31 22 | * @since JDK 1.8 23 | */ 24 | public class TableInfo implements Serializable{ 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | /**表名*/ 29 | private String name; 30 | 31 | /**表注释*/ 32 | private String comment; 33 | 34 | /**字段列表*/ 35 | private List fields = Lists.newArrayList(); 36 | 37 | /**主键*/ 38 | private TableField keyField; 39 | 40 | private String entityName; 41 | 42 | public TableInfo(String name, String comment) { 43 | this.name = name; 44 | this.comment = comment; 45 | } 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | 55 | public String getComment() { 56 | return comment; 57 | } 58 | 59 | public void setComment(String comment) { 60 | this.comment = comment; 61 | } 62 | 63 | public List getFields() { 64 | return fields; 65 | } 66 | 67 | public void setFields(List fields) { 68 | this.fields = fields; 69 | } 70 | 71 | public String getCapitalName() { 72 | return NamingStrategyType.toCapital(name); 73 | } 74 | 75 | public String getEntityName() { 76 | return entityName; 77 | } 78 | 79 | public void setEntityName(String entityName){ 80 | this.entityName = entityName; 81 | } 82 | 83 | public String getLetterEntityName(){ 84 | return NamingStrategyType.toLower(this.entityName); 85 | } 86 | 87 | public TableField getKeyField() { 88 | if (null != fields) keyField = fields.stream().filter(one -> one.getPrimary()).findFirst().orElse(new TableField()); 89 | return keyField; 90 | } 91 | 92 | /**是否包含日期类型*/ 93 | public boolean getHasDate() { 94 | if (null != fields) { 95 | return fields.stream().filter(one -> one.getPropertyType().equals("Date")).findAny().isPresent(); 96 | } 97 | return false; 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | StringBuilder builder = new StringBuilder(); 103 | builder.append("TableInfo [name=").append(name).append(", comment=").append(comment).append(", fields=") 104 | .append(fields).append(", keyField=").append(keyField).append("]"); 105 | return builder.toString(); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/config/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.config;/** 6 | * Created by Administrator on 2016/12/18. 7 | */ 8 | 9 | import com.fade.mybatis.enums.DbType; 10 | import com.fade.mybatis.utils.StringUtils; 11 | 12 | /** 13 | * Description: 数据库配置信息
14 | * 15 | * @author qingquanzhong 16 | * @version 1.0 17 | * @date: 2016-12-18 18 | * @since JDK 1.8 19 | */ 20 | public class DataSourceConfig { 21 | 22 | /**数据库类型*/ 23 | private DbType dbType; 24 | 25 | /**数据库url*/ 26 | private String url; 27 | 28 | /**数据库用户名*/ 29 | private String userName; 30 | 31 | /**数据库密码*/ 32 | private String password; 33 | 34 | /**驱动名*/ 35 | private String driverClass; 36 | 37 | /**数据库名*/ 38 | private String dbName; 39 | 40 | /**参数校验*/ 41 | public void argsCheck() { 42 | if(StringUtils.isBlank(this.driverClass) && null == this.dbType) 43 | throw new IllegalArgumentException("DbType or DriverClass can not be Null."); 44 | if (StringUtils.isNotBlank(this.driverClass)) { 45 | if (this.driverClass.contains("mysql")) 46 | this.dbType = DbType.mysql; 47 | else if(this.driverClass.contains("oracle")) 48 | this.dbType = DbType.oracle; 49 | else 50 | throw new IllegalArgumentException("just support mysql/oracle driver"); 51 | }else { 52 | this.driverClass = this.dbType.getDriverClassString(); 53 | } 54 | if (StringUtils.isBlank(this.url)) throw new IllegalArgumentException("url can not bu Null"); 55 | if (StringUtils.isBlank(this.userName)) throw new IllegalArgumentException("userName cant not be Null"); 56 | } 57 | 58 | 59 | public DbType getDbType() { 60 | return dbType; 61 | } 62 | 63 | public void setDbType(DbType dbType) { 64 | this.dbType = dbType; 65 | } 66 | 67 | public String getUrl() { 68 | return url; 69 | } 70 | 71 | public void setUrl(String url) { 72 | this.url = url; 73 | } 74 | 75 | public String getUserName() { 76 | return userName; 77 | } 78 | 79 | public void setUserName(String userName) { 80 | this.userName = userName; 81 | } 82 | 83 | public String getPassword() { 84 | return password; 85 | } 86 | 87 | public void setPassword(String password) { 88 | this.password = password; 89 | } 90 | 91 | public String getDriverClass() { 92 | return driverClass; 93 | } 94 | 95 | public void setDriverClass(String driverClass) { 96 | this.driverClass = driverClass; 97 | } 98 | 99 | 100 | public String getDbName() { 101 | return dbName; 102 | } 103 | 104 | 105 | public void setDbName(String dbName) { 106 | this.dbName = dbName; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/enums/DbType.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | 6 | 7 | 8 | package com.fade.mybatis.enums; 9 | 10 | /** 11 | * Created by qingquanzhong on 2016/12/18. 12 | */ 13 | 14 | import com.fade.mybatis.utils.CollectionUtil; 15 | import com.fade.mybatis.utils.StringUtils; 16 | 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | /** 21 | * Description: 数据库类型
22 | * 23 | * @author qingquanzhong 24 | * @version 1.0 25 | * @date: 2016-12-18 12:00:00 26 | * @since JDK 1.8 27 | */ 28 | public enum DbType { 29 | mysql { 30 | @Override 31 | public String getValue() { 32 | return "mysql"; 33 | } 34 | 35 | /**ip,port,database,characterEncoding 占位符处理*/ 36 | @Override 37 | public String getUrl() { 38 | return "jdbc:mysql://%s:%s/%s?useUnicode=true&characterEncoding=%s&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"; 39 | } 40 | /**新版驱动*/ 41 | @Override 42 | public String getDriverClassString() { 43 | return "com.mysql.cj.jdbc.Driver"; 44 | } 45 | 46 | @Override 47 | public String getBackDriverClassString() { 48 | return "com.mysql.jdbc.Driver"; 49 | } 50 | 51 | @Override 52 | public String getDesc() { 53 | return "Mysql DB"; 54 | } 55 | }, 56 | oracle { 57 | @Override 58 | public String getValue() { 59 | return "oracle"; 60 | } 61 | 62 | /**ip,port,servicename*/ 63 | @Override 64 | public String getUrl() { 65 | return "jdbc:oracle:thin:@%s:%s:%s"; 66 | } 67 | 68 | @Override 69 | public String getDriverClassString() { 70 | return "oracle.jdbc.driver.OracleDriver"; 71 | } 72 | 73 | @Override 74 | public String getBackDriverClassString() { 75 | return getDriverClassString(); 76 | } 77 | 78 | @Override 79 | public String getDesc() { 80 | return "Oracle DB"; 81 | } 82 | }; 83 | 84 | public abstract String getDesc(); 85 | 86 | public abstract String getValue(); 87 | 88 | public abstract String getUrl(); 89 | 90 | public abstract String getDriverClassString(); 91 | 92 | public abstract String getBackDriverClassString(); 93 | 94 | private static final Map map; 95 | 96 | static { 97 | map = new HashMap<>(CollectionUtil.capacitySize(values().length)); 98 | for (DbType type : values()) { 99 | map.put(type.getValue(), type); 100 | } 101 | } 102 | 103 | /**根据key获取枚举,未匹配到则返回空*/ 104 | public static DbType get(String value) { 105 | if (StringUtils.isBlank(value)) return null; 106 | return map.get(value); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/service/in/LocalDBHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.fade.mybatis.service.in; 5 | 6 | import java.time.LocalDateTime; 7 | import java.time.ZoneId; 8 | import java.util.List; 9 | import java.util.concurrent.ConcurrentMap; 10 | import java.util.stream.Collectors; 11 | 12 | import org.mapdb.DB; 13 | import org.mapdb.DBMaker; 14 | import org.mapdb.HTreeMap; 15 | import org.mapdb.Serializer; 16 | import org.mapdb.serializer.SerializerCompressionWrapper; 17 | 18 | import com.alibaba.fastjson.JSON; 19 | import com.fade.mybatis.vo.DBConfigVo; 20 | import com.google.common.base.Strings; 21 | 22 | /** 23 | * @author qingquanzhong 24 | * 本地数据库工具 25 | */ 26 | public class LocalDBHelper { 27 | 28 | private static final String FILE_NAME = "DBConfig.db"; 29 | 30 | private static final String MAP_NAME = "DBConnection"; 31 | 32 | private static DB db = makeDB(FILE_NAME); 33 | 34 | public static List list() { 35 | HTreeMap map = db.hashMap(MAP_NAME, Serializer.STRING, Serializer.STRING).createOrOpen(); 36 | List vos = map.getValues().stream().map(one -> JSON.parseObject(one, DBConfigVo.class)).collect(Collectors.toList()); 37 | return vos; 38 | } 39 | 40 | public static void remove(String id) { 41 | if (Strings.isNullOrEmpty(id)) return ; 42 | HTreeMap map = db.hashMap(MAP_NAME, Serializer.STRING, Serializer.STRING).createOrOpen(); 43 | map.remove(id); 44 | db.commit(); 45 | } 46 | 47 | public static void update(DBConfigVo config){ 48 | if (null == config || Strings.isNullOrEmpty(config.getId())) return ; 49 | HTreeMap map = db.hashMap(MAP_NAME, Serializer.STRING, Serializer.STRING).createOrOpen(); 50 | map.replace(config.getId(), JSON.toJSONString(config)); 51 | db.commit(); 52 | } 53 | 54 | 55 | public static void save(DBConfigVo config) { 56 | if (null == config) throw new IllegalArgumentException("保存配置不能为空"); 57 | ConcurrentMap map = db.hashMap(MAP_NAME, Serializer.STRING, Serializer.STRING).valueSerializer(new SerializerCompressionWrapper<>(Serializer.STRING)).createOrOpen(); 58 | if (Strings.isNullOrEmpty(config.getId())) config.setId(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() + ""); 59 | map.put(config.getId(), JSON.toJSONString(config)); 60 | db.commit(); 61 | } 62 | 63 | public static DBConfigVo get(String configName) { 64 | if (Strings.isNullOrEmpty(configName)) return null; 65 | HTreeMap map = db.hashMap(MAP_NAME, Serializer.STRING, Serializer.STRING).createOrOpen(); 66 | String content = map.get(configName); 67 | if (Strings.isNullOrEmpty(content)) return null; 68 | return JSON.parseObject(content, DBConfigVo.class); 69 | } 70 | 71 | private static DB makeDB(String file) { 72 | return Strings.isNullOrEmpty(file) ? DBMaker.memoryDB().checksumHeaderBypass().closeOnJvmShutdown().make() : DBMaker.fileDB(file).closeOnJvmShutdown().checksumHeaderBypass().make(); 73 | } 74 | 75 | protected static void closeDB(DB db) { 76 | if (null != db) db.close(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/dto/PageDto.java: -------------------------------------------------------------------------------- 1 | /** 2 | */ 3 | package com.fade.mybatis.dto; 4 | 5 | import java.io.Serializable; 6 | import java.util.List; 7 | 8 | import com.google.common.collect.Lists; 9 | 10 | /** 11 | * Description: 分页对象
12 | * 13 | * @author qingquanzhong 14 | * @date: 2017年09月02日 00:17:05 15 | * @version 1.0 16 | * @since JDK 1.87 17 | */ 18 | public class PageDto implements Serializable { 19 | 20 | private static final long serialVersionUID = 2479081883631073018L; 21 | 22 | /** 结果列表 */ 23 | private List values; 24 | 25 | /** 总记录数 */ 26 | private Integer totalCount; 27 | 28 | /** 每页数目 */ 29 | private Integer pageSize; 30 | 31 | /** 页码 */ 32 | private Integer pageNum; 33 | 34 | /** 总页数 */ 35 | private Integer totalPages; 36 | 37 | /** 当前页记录数 */ 38 | private Integer pageCout; 39 | 40 | @SuppressWarnings("unused") 41 | private PageDto(){ 42 | } 43 | 44 | /** pageSize:每页数目,pageNum:页码,values:结果集,totalCount:总记录数 */ 45 | public PageDto(Integer pageSize, Integer pageNum, List values, Integer totalCount) { 46 | this.pageSize = pageSize; 47 | this.pageNum = pageNum; 48 | doCheck(); 49 | this.totalCount = totalCount; 50 | this.values = values == null ? Lists.newArrayList() :values; 51 | setTotalPage(); 52 | } 53 | 54 | /**设置总记录数*/ 55 | private void setTotalPage() { 56 | if (this.getTotalCount() == 0) 57 | this.totalPages = 0; 58 | else 59 | this.totalPages = this.getTotalCount() / this.getPageSize() + (this.getTotalCount() % this.getPageSize() == 0 ? 0 : 1); 60 | } 61 | 62 | private void doCheck() { 63 | if (null == this.pageSize || this.pageSize < 1) { 64 | throw new IllegalArgumentException("the pageSize value was illegal."); 65 | } 66 | if (null == this.pageNum || this.pageNum < 1) { 67 | throw new IllegalArgumentException("the pageNum value was illegal."); 68 | } 69 | } 70 | 71 | /** {@linkplain #values} */ 72 | public List getValues() { 73 | return null == values ? Lists.newArrayList() : values; 74 | } 75 | 76 | /** {@linkplain #totalCount} */ 77 | public Integer getTotalCount() { 78 | if (null == totalCount || totalCount <= 0) 79 | totalCount = 0; 80 | return totalCount; 81 | } 82 | 83 | /** {@linkplain #pageSize} */ 84 | public Integer getPageSize() { 85 | return pageSize; 86 | } 87 | 88 | /** {@linkplain #pageNum} */ 89 | public Integer getPageNum() { 90 | return pageNum; 91 | } 92 | 93 | /** {@linkplain #totalPages} */ 94 | public Integer getTotalPages() { 95 | return totalPages; 96 | } 97 | 98 | /** {@linkplain #pageCout} */ 99 | public Integer getPageCout() { 100 | pageCout = null == values ? 0 : values.size(); 101 | return pageCout; 102 | } 103 | 104 | @Override 105 | public String toString() { 106 | return "Page [values=" + values + ", totalCount=" + totalCount + ", pageSize=" + pageSize + ", pageNum=" 107 | + pageNum + ", totalPages=" + totalPages + ", pageCout=" + pageCout + "]"; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/vo/GeneratorVo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.fade.mybatis.vo; 5 | 6 | import java.io.Serializable; 7 | import java.util.List; 8 | 9 | /** 10 | * @author qingquanzhong 11 | * 12 | */ 13 | public class GeneratorVo implements Serializable{ 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | private String author; 18 | 19 | /** 接口目录 */ 20 | private String logicServiceItfPackage; 21 | 22 | /** 服务目录*/ 23 | private String logicServicePackage; 24 | 25 | /**工程目录*/ 26 | private String projectFolder; 27 | 28 | /**实体目录*/ 29 | private String domainPackage; 30 | 31 | /**mapper目录*/ 32 | private String mapperPackage; 33 | 34 | /**生成注释*/ 35 | private Boolean generateComment = Boolean.TRUE; 36 | 37 | /**建造者模式*/ 38 | private Boolean useBuilderModel = Boolean.TRUE; 39 | 40 | /**命名策略 默认驼峰法*/ 41 | private String nameStrategy; 42 | 43 | /**指定前缀/后缀*/ 44 | private String prefix; 45 | 46 | private List tableNames; 47 | 48 | public String getAuthor() { 49 | return author; 50 | } 51 | 52 | public void setAuthor(String author) { 53 | this.author = author; 54 | } 55 | 56 | public String getLogicServiceItfPackage() { 57 | return logicServiceItfPackage; 58 | } 59 | 60 | public void setLogicServiceItfPackage(String logicServiceItfPackage) { 61 | this.logicServiceItfPackage = logicServiceItfPackage; 62 | } 63 | 64 | public String getLogicServicePackage() { 65 | return logicServicePackage; 66 | } 67 | 68 | public void setLogicServicePackage(String logicServicePackage) { 69 | this.logicServicePackage = logicServicePackage; 70 | } 71 | 72 | public String getProjectFolder() { 73 | return projectFolder; 74 | } 75 | 76 | public void setProjectFolder(String projectFolder) { 77 | this.projectFolder = projectFolder; 78 | } 79 | 80 | public String getDomainPackage() { 81 | return domainPackage; 82 | } 83 | 84 | public void setDomainPackage(String domainPackage) { 85 | this.domainPackage = domainPackage; 86 | } 87 | 88 | public String getMapperPackage() { 89 | return mapperPackage; 90 | } 91 | 92 | public void setMapperPackage(String mapperPackage) { 93 | this.mapperPackage = mapperPackage; 94 | } 95 | 96 | public Boolean getGenerateComment() { 97 | return generateComment; 98 | } 99 | 100 | public void setGenerateComment(Boolean generateComment) { 101 | this.generateComment = generateComment; 102 | } 103 | 104 | public Boolean getUseBuilderModel() { 105 | return useBuilderModel; 106 | } 107 | 108 | public void setUseBuilderModel(Boolean useBuilderModel) { 109 | this.useBuilderModel = useBuilderModel; 110 | } 111 | 112 | public String getNameStrategy() { 113 | return nameStrategy; 114 | } 115 | 116 | public void setNameStrategy(String nameStrategy) { 117 | this.nameStrategy = nameStrategy; 118 | } 119 | 120 | public String getPrefix() { 121 | return prefix; 122 | } 123 | 124 | public void setPrefix(String prefix) { 125 | this.prefix = prefix; 126 | } 127 | 128 | public List getTableNames() { 129 | return tableNames; 130 | } 131 | 132 | public void setTableNames(List tableNames) { 133 | this.tableNames = tableNames; 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/vo/DBConfigVo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.fade.mybatis.vo; 5 | 6 | import java.io.Serializable; 7 | 8 | import com.fade.mybatis.enums.DbType; 9 | import com.fade.mybatis.enums.EncodeType; 10 | import com.google.common.base.Strings; 11 | 12 | /** 13 | * @author qingquanzhong 14 | * 15 | */ 16 | public class DBConfigVo implements Serializable { 17 | 18 | private static final long serialVersionUID = -3442349954458451410L; 19 | 20 | private String id; 21 | 22 | /** 连接名 */ 23 | private String connectionName; 24 | 25 | private String dbType; 26 | 27 | /** 主机名或IP */ 28 | private String host; 29 | 30 | /** 端口号 */ 31 | private Integer port; 32 | 33 | /** 数据库名 */ 34 | private String databaseName; 35 | 36 | /** 用户名 */ 37 | private String userName; 38 | 39 | /** 密码 */ 40 | private String password; 41 | 42 | /** 编码 */ 43 | private String encode; 44 | 45 | private String fullURL; 46 | 47 | public String getDbType() { 48 | return dbType; 49 | } 50 | 51 | public void setDbType(String dbType) { 52 | this.dbType = dbType; 53 | } 54 | 55 | public String getId() { 56 | return id; 57 | } 58 | 59 | public void setId(String id) { 60 | this.id = id; 61 | } 62 | 63 | public String getHost() { 64 | return host; 65 | } 66 | 67 | public void setHost(String host) { 68 | this.host = host; 69 | } 70 | 71 | public Integer getPort() { 72 | return port; 73 | } 74 | 75 | public void setPort(Integer port) { 76 | this.port = port; 77 | } 78 | 79 | 80 | public String getDatabaseName() { 81 | return databaseName; 82 | } 83 | 84 | public void setDatabaseName(String databaseName) { 85 | this.databaseName = databaseName; 86 | } 87 | 88 | public String getUserName() { 89 | return userName; 90 | } 91 | 92 | public void setUserName(String userName) { 93 | this.userName = userName; 94 | } 95 | 96 | public String getPassword() { 97 | return password; 98 | } 99 | 100 | public void setPassword(String password) { 101 | this.password = password; 102 | } 103 | 104 | public String getEncode() { 105 | return encode; 106 | } 107 | 108 | public void setEncode(String encode) { 109 | this.encode = encode; 110 | } 111 | 112 | public String getConnectionName() { 113 | return connectionName; 114 | } 115 | 116 | public void setConnectionName(String connectionName) { 117 | this.connectionName = connectionName; 118 | } 119 | 120 | public String getFullURL() { 121 | if (DbType.mysql.getValue().equals(this.dbType)) { 122 | fullURL = String.format(DbType.mysql.getUrl(), this.host, this.port, this.databaseName, Strings.isNullOrEmpty(this.encode) ? this.encode :EncodeType.UTF8.getValue()); 123 | }else if (DbType.oracle.getValue().equals(this.dbType)){ 124 | fullURL = String.format(DbType.oracle.getUrl(), this.host, this.port, this.databaseName); 125 | } 126 | return fullURL; 127 | } 128 | 129 | @Override 130 | public String toString() { 131 | StringBuilder builder = new StringBuilder(); 132 | builder.append("DBConfigVo [id=").append(id).append(", connectionName=").append(connectionName) 133 | .append(", host=").append(host).append(", port=").append(port).append(", databaseName=").append(databaseName) 134 | .append(", userName=").append(userName).append(", password=").append(password).append(", encode=") 135 | .append(encode).append("]"); 136 | return builder.toString(); 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/enums/TemplateType.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.enums;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | import com.fade.mybatis.utils.CollectionUtil; 10 | import com.fade.mybatis.utils.StringUtils; 11 | 12 | import java.io.File; 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | /** 17 | * Description: 模版类型
18 | * 19 | * @author qingquanzhong 20 | * @version 1.0 21 | * @date: 2016-12-18 18:06:35 22 | * @since JDK 1.8 23 | */ 24 | public enum TemplateType { 25 | 26 | mapper_xml { 27 | @Override 28 | public String getDesc() { 29 | return "Mapper xml配置模版"; 30 | } 31 | 32 | @Override 33 | public String getValue() { 34 | 35 | return "mapper_xml"; 36 | } 37 | 38 | @Override 39 | public String getPathTmeplate() { 40 | return new StringBuilder(20).append("%s").append(File.separator).append("%s").append(File.separator).append("%sMapper.xml").toString(); 41 | } 42 | },mapper_java { 43 | @Override 44 | public String getDesc() { 45 | return "Mapper java 接口模版"; 46 | } 47 | 48 | @Override 49 | public String getValue() { 50 | 51 | return "mapper_java"; 52 | } 53 | 54 | @Override 55 | public String getPathTmeplate() { 56 | return new StringBuilder(12).append("%s").append(File.separator).append("%s").append(File.separator).append("%sMapper.java").toString(); 57 | } 58 | },entity_java { 59 | @Override 60 | public String getDesc() { 61 | return "Entity 模版"; 62 | } 63 | 64 | @Override 65 | public String getValue() { 66 | 67 | return "entity_java"; 68 | } 69 | 70 | @Override 71 | public String getPathTmeplate() { 72 | return new StringBuilder(12).append("%s").append(File.separator).append("%s").append(File.separator).append("%sEntity.java").toString(); 73 | } 74 | },service_java { 75 | @Override 76 | public String getDesc() { 77 | return "Service 模版"; 78 | } 79 | 80 | @Override 81 | public String getValue() { 82 | 83 | return "service_java"; 84 | } 85 | 86 | @Override 87 | public String getPathTmeplate() { 88 | return new StringBuilder(12).append("%s").append(File.separator).append("%s").append(File.separator).append("%sLogicService.java").toString(); 89 | } 90 | }, 91 | service_itf_java { 92 | @Override 93 | public String getDesc() { 94 | return "Service 接口 模版"; 95 | } 96 | 97 | @Override 98 | public String getValue() { 99 | 100 | return "service_itf_java"; 101 | } 102 | 103 | @Override 104 | public String getPathTmeplate() { 105 | return new StringBuilder(12).append("%s").append(File.separator).append("%s").append(File.separator).append("I%sLogicService.java").toString(); 106 | } 107 | }, 108 | controller_java { 109 | @Override 110 | public String getDesc() { 111 | return "Controller 模版"; 112 | } 113 | 114 | @Override 115 | public String getValue() { 116 | 117 | return "controller_java"; 118 | } 119 | 120 | @Override 121 | public String getPathTmeplate() { 122 | return new StringBuilder(12).append("%s").append(File.separator).append("%s").append(File.separator).append("%sController.java").toString(); 123 | } 124 | }; 125 | 126 | public abstract String getValue(); 127 | 128 | public abstract String getDesc(); 129 | 130 | public abstract String getPathTmeplate(); 131 | 132 | private static final Map map; 133 | 134 | static { 135 | map = new HashMap<>(CollectionUtil.capacitySize(values().length)); 136 | for (TemplateType type : values()) { 137 | map.put(type.getValue(), type); 138 | } 139 | } 140 | 141 | /**根据key获取枚举,未匹配到则返回空*/ 142 | public static TemplateType get(String value) { 143 | if (StringUtils.isBlank(value)) return null; 144 | return map.get(value); 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/config/builder/DataSourceConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.config.builder;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | import com.fade.mybatis.config.DataSourceConfig; 10 | import com.fade.mybatis.enums.DbType; 11 | import com.fade.mybatis.enums.EncodeType; 12 | import com.fade.mybatis.utils.StringUtils; 13 | 14 | /** 15 | * Description: 数据库配置构造器
16 | * (host,port,databaseName,dbType,userName,password) 17 | * @author qingquanzhong 18 | * @version 1.0 19 | * @date: 2016-12-18 13:12:44 20 | * @since JDK 1.8 21 | */ 22 | public class DataSourceConfigBuilder { 23 | 24 | /**主机名或ip*/ 25 | private String host; 26 | 27 | /**端口号*/ 28 | private Integer port; 29 | 30 | /**数据库名*/ 31 | private String databaseName; 32 | 33 | /**数据库类型*/ 34 | private DbType dbType; 35 | 36 | /**数据库用户名*/ 37 | private String userName; 38 | 39 | /**数据库密码*/ 40 | private String password; 41 | 42 | /**驱动名*/ 43 | private String driverClass; 44 | 45 | /**编码*/ 46 | private EncodeType encodeType = EncodeType.UTF8; 47 | 48 | public static DataSourceConfigBuilder newInstance() { 49 | return new DataSourceConfigBuilder(); 50 | } 51 | 52 | public DataSourceConfig builder(){ 53 | DataSourceConfig config = new DataSourceConfig(); 54 | init(); 55 | config.setDbType(this.dbType); 56 | config.setDriverClass(this.driverClass); 57 | config.setUrl(this.processUrl()); 58 | config.setUserName(this.userName); 59 | config.setPassword(this.password); 60 | config.setDbName(this.databaseName); 61 | config.argsCheck(); 62 | return config; 63 | } 64 | 65 | private void init() { 66 | if (DbType.mysql.equals(this.dbType)) { 67 | if (null == this.port) this.port = 3306; 68 | }else if (DbType.oracle.equals(this.dbType)){ 69 | if (null == this.port) this.port = 1521; 70 | } 71 | if (StringUtils.isBlank(this.driverClass) && null != this.dbType) 72 | this.driverClass = this.dbType.getDriverClassString(); 73 | if (null == this.dbType && StringUtils.isNotBlank(this.driverClass)) { 74 | if (this.driverClass.contains("mysql")) 75 | this.dbType = DbType.mysql; 76 | else if (this.driverClass.contains("oracle")) 77 | this.dbType = DbType.oracle; 78 | } 79 | } 80 | 81 | private String processUrl() { 82 | if (DbType.mysql.equals(this.dbType)) { 83 | return String.format(this.dbType.getUrl(), this.host, this.port, this.databaseName, (null != this.encodeType ? this.encodeType :EncodeType.UTF8).getValue()); 84 | }else if (DbType.oracle.equals(this.dbType)){ 85 | return String.format(this.dbType.getUrl(), this.host, this.port, this.databaseName); 86 | } 87 | return null; 88 | } 89 | 90 | public DataSourceConfigBuilder setDbType(DbType dbType) { 91 | this.dbType = dbType; 92 | return this; 93 | } 94 | 95 | public DataSourceConfigBuilder setUserName(String userName) { 96 | this.userName = userName; 97 | return this; 98 | } 99 | 100 | public DataSourceConfigBuilder setPassword(String password) { 101 | this.password = password; 102 | return this; 103 | } 104 | 105 | /**可不设置会根据DbType自动匹配*/ 106 | public DataSourceConfigBuilder setDriverClass(String driverClass) { 107 | this.driverClass = driverClass; 108 | return this; 109 | } 110 | 111 | public DataSourceConfigBuilder setHost(String host) { 112 | this.host = host; 113 | return this; 114 | } 115 | 116 | public DataSourceConfigBuilder setPort(Integer port) { 117 | this.port = port; 118 | return this; 119 | } 120 | 121 | public DataSourceConfigBuilder setEncodeType(EncodeType encodeType) { 122 | this.encodeType = encodeType; 123 | return this; 124 | } 125 | 126 | public DataSourceConfigBuilder setDatabaseName(String databaseName) { 127 | this.databaseName = databaseName; 128 | return this; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/enums/NamingStrategyType.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | 6 | 7 | 8 | package com.fade.mybatis.enums; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | import com.fade.mybatis.utils.CollectionUtil; 14 | 15 | /** 16 | * Created by qingquanzhong on 2016/12/19. 17 | */ 18 | 19 | import com.fade.mybatis.utils.ConstansValue; 20 | import com.fade.mybatis.utils.StringUtils; 21 | 22 | /** 23 | * Description: 命名策略
24 | * 25 | * @author qingquanzhong 26 | * @version 1.0 27 | * @date: 2016-12-18 19:00:00 28 | * @since JDK 1.8 29 | */ 30 | public enum NamingStrategyType { 31 | 32 | /** 原样 */ 33 | original, 34 | 35 | /** 去掉前缀 */ 36 | remove_prefix, 37 | 38 | /** 加固定前缀 */ 39 | plus_prefix, 40 | 41 | /** 下划线转驼峰 */ 42 | underline_to_camel, 43 | 44 | /** 去掉前缀转驼峰 */ 45 | remove_prefix_to_camel, 46 | 47 | /** 加前缀转驼峰 */ 48 | plus_prefix_to_camel; 49 | 50 | public static String converNaming(String source, NamingStrategyType type, String prefix) { 51 | if (null == type || original.equals(type)) return source; 52 | if (remove_prefix.equals(type)) { 53 | source = removePrefix(source, prefix); 54 | } else if (plus_prefix.equals(type)) { 55 | source = plusPrefix(source, prefix); 56 | } else if (underline_to_camel.equals(type)) { 57 | source = underlineToCamel(source); 58 | } else if (remove_prefix_to_camel.equals(type)) { 59 | source = removePrefixAnd2Camel(source, prefix); 60 | } else if (plus_prefix_to_camel.equals(type)) { 61 | source = plusPrefixAnd2Camel(source, prefix); 62 | } 63 | return source; 64 | } 65 | 66 | /**增加前缀*/ 67 | public static String plusPrefix(String target, String prefix) { 68 | if (StringUtils.isBlank(target) || StringUtils.isBlank(prefix)) { 69 | return target; 70 | } 71 | return prefix + target; 72 | } 73 | 74 | /**加前缀再转驼峰*/ 75 | public static String plusPrefixAnd2Camel(String target, String prefix) { 76 | return underlineToCamel(plusPrefix(target, prefix)); 77 | } 78 | 79 | /**去掉固定前缀*/ 80 | public static String removePrefix(String target, String prefix) { 81 | if (StringUtils.isBlank(target) || StringUtils.isBlank(prefix)) { 82 | return target; 83 | } 84 | return target.trim().replaceFirst(prefix.trim(), ""); 85 | } 86 | 87 | /**去掉前缀再转驼峰*/ 88 | public static String removePrefixAnd2Camel(String target, String prefix) { 89 | return underlineToCamel(removePrefix(target, prefix)); 90 | } 91 | 92 | /**首字母大写*/ 93 | public static String toCapital(String target) { 94 | if (StringUtils.isBlank(target)) return target; 95 | return target.substring(0, 1).toUpperCase() + target.substring(1); 96 | } 97 | 98 | /**首字母小写*/ 99 | public static String toLower(String target) { 100 | if (StringUtils.isBlank(target)) return target; 101 | return target.substring(0, 1).toLowerCase() + target.substring(1); 102 | } 103 | 104 | /**下划线转驼峰*/ 105 | public static String underlineToCamel(String param) { 106 | if (StringUtils.isBlank(param)) { 107 | return ""; 108 | } 109 | int len = param.length(); 110 | StringBuilder sb = new StringBuilder(len); 111 | for (int i = 0; i < len; i++) { 112 | char c = param.charAt(i); 113 | if (ConstansValue.UNDERLINE == c) { 114 | if (++i < len) { 115 | sb.append(Character.toUpperCase(param.charAt(i))); 116 | } 117 | } else { 118 | sb.append(c); 119 | } 120 | } 121 | return sb.toString(); 122 | } 123 | 124 | private static final Map map; 125 | 126 | static { 127 | map = new HashMap<>(CollectionUtil.capacitySize(values().length)); 128 | for (NamingStrategyType type : values()) { 129 | map.put(type.name(), type); 130 | } 131 | } 132 | 133 | /**根据key获取枚举,未匹配到则返回空*/ 134 | public static NamingStrategyType get(String value) { 135 | if (StringUtils.isBlank(value)) return null; 136 | return map.get(value); 137 | } 138 | 139 | } 140 | 141 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/model/TableField.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.model;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | import java.io.Serializable; 10 | 11 | import com.fade.mybatis.enums.NamingStrategyType; 12 | 13 | /** 14 | * Description: {一句话描述类是干什么的}
15 | * 16 | * @author qingquanzhong 17 | * @version 1.0 18 | * @date: 2016-12-18 12:11:32 19 | * @since JDK 1.8 20 | */ 21 | public class TableField implements Serializable { 22 | 23 | private static final long serialVersionUID = 4572636218095513192L; 24 | 25 | /**列名*/ 26 | private String name; 27 | 28 | /**注释*/ 29 | private String comment; 30 | 31 | /**类型*/ 32 | private String jdbcType; 33 | 34 | /**默认值*/ 35 | private Object defaultValue; 36 | 37 | /**是否可Null*/ 38 | private Boolean nullAble = Boolean.TRUE; 39 | 40 | /**对应属性名*/ 41 | private String propertyName; 42 | 43 | /**属性类型*/ 44 | private String propertyType; 45 | 46 | /**列类型 */ 47 | private String typeName; 48 | 49 | /**是否主键*/ 50 | private Boolean primary = Boolean.FALSE; 51 | 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | public String getComment() { 61 | return comment; 62 | } 63 | 64 | public void setComment(String comment) { 65 | this.comment = comment; 66 | } 67 | 68 | public String getJdbcType() { 69 | return jdbcType; 70 | } 71 | 72 | public void setJdbcType(String jdbcType) { 73 | this.jdbcType = jdbcType; 74 | } 75 | 76 | public String getPropertyName() { 77 | return propertyName; 78 | } 79 | 80 | public void setPropertyName(String propertyName) { 81 | this.propertyName = propertyName; 82 | } 83 | 84 | public String getPropertyType() { 85 | return propertyType; 86 | } 87 | 88 | /**{@linkplain #propertyType}*/ 89 | public void setPropertyType(String propertyType) { 90 | this.propertyType = propertyType; 91 | } 92 | 93 | public Object getDefaultValue() { 94 | return defaultValue; 95 | } 96 | 97 | public void setDefaultValue(Object defaultValue) { 98 | this.defaultValue = defaultValue; 99 | } 100 | 101 | public Boolean getNullAble() { 102 | return nullAble; 103 | } 104 | 105 | public void setNullAble(Boolean nullAble) { 106 | this.nullAble = nullAble; 107 | } 108 | 109 | public Boolean getPrimary() { 110 | return primary; 111 | } 112 | 113 | public void setPrimary(Boolean primary) { 114 | this.primary = primary; 115 | } 116 | 117 | public String getTypeName() { 118 | return typeName; 119 | } 120 | 121 | public void setTypeName(String typeName) { 122 | this.typeName = typeName; 123 | } 124 | 125 | public String getCapitalPropertyName() { 126 | return NamingStrategyType.toCapital(propertyName); 127 | } 128 | 129 | /**为set/get准备*/ 130 | public String getCapitalSetPropertyName(){ 131 | return NamingStrategyType.plusPrefix(NamingStrategyType.toCapital(propertyName), "set"); 132 | } 133 | 134 | public String getCapitalGetPropertyName(){ 135 | return NamingStrategyType.plusPrefix(NamingStrategyType.toCapital(propertyName), "get"); 136 | } 137 | 138 | /**对Boolean is开头的属性处理*/ 139 | public String getBooleanPropertyName() { 140 | return NamingStrategyType.toLower(NamingStrategyType.removePrefix(propertyName, "is")); 141 | } 142 | 143 | public String getBooleanSetPropertyName() { 144 | return NamingStrategyType.plusPrefix(NamingStrategyType.toCapital(NamingStrategyType.removePrefix(propertyName, "is")), "set"); 145 | } 146 | 147 | @Override 148 | public String toString() { 149 | StringBuilder builder = new StringBuilder(); 150 | builder.append("TableField [name=").append(name).append(", comment=").append(comment).append(", jdbcType=") 151 | .append(jdbcType).append(", defaultValue=").append(defaultValue).append(", nullAble=").append(nullAble) 152 | .append(", propertyName=").append(propertyName).append(", propertyType=").append(propertyType) 153 | .append(", primary=").append(primary).append("]"); 154 | return builder.toString(); 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/config/GeneratorConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.config; 6 | 7 | import java.io.File; 8 | import java.io.Serializable; 9 | 10 | import com.fade.mybatis.enums.NamingStrategyType; 11 | import com.fade.mybatis.utils.StringUtils; 12 | import com.google.common.base.Strings; 13 | 14 | /** 15 | * Created by Administrator on 2016/12/18. 16 | */ 17 | 18 | /** 19 | * Description:项目自动生成总体配置
20 | * 21 | * @author qingquanzhong 22 | * @version 1.0 23 | * @date: 2016-12-18 06:10:23 24 | * @since JDK 1.8 25 | */ 26 | public class GeneratorConfig implements Serializable { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | /**作者*/ 31 | private String author; 32 | 33 | /** 接口目录 */ 34 | private String logicServiceItfPackage; 35 | 36 | /** 服务目录*/ 37 | private String logicServicePackage; 38 | 39 | /**工程目录*/ 40 | private String projectFolder; 41 | 42 | /**实体目录*/ 43 | private String domainPackage; 44 | 45 | /**mapper目录*/ 46 | private String mapperPackage; 47 | 48 | /**生成注释*/ 49 | private Boolean generateComment = Boolean.TRUE; 50 | 51 | /**建造者模式*/ 52 | private Boolean useBuilderModel = Boolean.TRUE; 53 | 54 | /**命名策略 默认驼峰法*/ 55 | private NamingStrategyType nameStrategy; 56 | 57 | /**指定前缀/后缀*/ 58 | private String prefix; 59 | 60 | /**模板路径配置*/ 61 | private TemplateConfig templateConfig; 62 | 63 | public NamingStrategyType getNameStrategy() { 64 | return nameStrategy == null ? NamingStrategyType.underline_to_camel : nameStrategy; 65 | } 66 | 67 | public GeneratorConfig setNameStrategy(NamingStrategyType nameStrategy) { 68 | this.nameStrategy = nameStrategy; 69 | return this; 70 | } 71 | 72 | public String getPrefix() { 73 | return prefix; 74 | } 75 | 76 | public GeneratorConfig setPrefix(String prefix) { 77 | this.prefix = prefix; 78 | return this; 79 | } 80 | 81 | public String getLogicServiceItfPackage() { 82 | return logicServiceItfPackage; 83 | } 84 | 85 | public GeneratorConfig setLogicServiceItfPackage(String logicServiceItfPackage) { 86 | this.logicServiceItfPackage = logicServiceItfPackage; 87 | return this; 88 | } 89 | 90 | public String getLogicServicePackage() { 91 | return logicServicePackage; 92 | } 93 | 94 | public GeneratorConfig setLogicServicePackage(String logicServicePackage) { 95 | this.logicServicePackage = logicServicePackage; 96 | return this; 97 | } 98 | 99 | public String getProjectFolder() { 100 | return projectFolder; 101 | } 102 | 103 | public GeneratorConfig setProjectFolder(String projectFolder) { 104 | this.projectFolder = projectFolder; 105 | return this; 106 | } 107 | 108 | public String getDomainPackage() { 109 | return domainPackage; 110 | } 111 | 112 | public GeneratorConfig setDomainPackage(String domainPackage) { 113 | this.domainPackage = domainPackage; 114 | return this; 115 | } 116 | 117 | public String getMapperPackage() { 118 | return mapperPackage; 119 | } 120 | 121 | /**xml配置路径*/ 122 | public String getXmlMapperPackage() { 123 | return StringUtils.concat(mapperPackage, "xml", File.separator); 124 | } 125 | 126 | public GeneratorConfig setMapperPackage(String mapperPackage) { 127 | this.mapperPackage = mapperPackage; 128 | return this; 129 | } 130 | 131 | public Boolean getGenerateComment() { 132 | return generateComment; 133 | } 134 | 135 | public GeneratorConfig setGenerateComment(Boolean generateComment) { 136 | this.generateComment = generateComment; 137 | return this; 138 | } 139 | 140 | public Boolean getUseBuilderModel() { 141 | return useBuilderModel == null ? Boolean.TRUE : useBuilderModel; 142 | } 143 | 144 | public GeneratorConfig setUseBuilderModel(Boolean useBuilderModel) { 145 | this.useBuilderModel = useBuilderModel; 146 | return this; 147 | } 148 | 149 | public String getAuthor() { 150 | return Strings.isNullOrEmpty(author) ? "qingquanzhong@126.com" : author; 151 | } 152 | 153 | public GeneratorConfig setAuthor(String author) { 154 | this.author = author; 155 | return this; 156 | } 157 | 158 | public TemplateConfig getTemplateConfig() { 159 | return templateConfig; 160 | } 161 | 162 | public GeneratorConfig setTemplateConfig(TemplateConfig templateConfig) { 163 | this.templateConfig = templateConfig; 164 | return this; 165 | } 166 | 167 | } 168 | -------------------------------------------------------------------------------- /src/main/resources/logicService.java.vm: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package ${package.LogicService}; 5 | 6 | import java.util.List; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import com.github.pagehelper.Page; 11 | import com.github.pagehelper.PageHelper; 12 | 13 | import com.google.common.collect.Lists; 14 | import ${package.Mapper}.${table.entityName}Mapper; 15 | import ${package.Entity}.${entityName}; 16 | 17 | /** 18 | * Description: ${table.comment} 逻辑服务类
19 | * 不做业务校验,参数校验统一放到前置的Service中 20 | * @author ${author} 21 | * @version 1.0 22 | * @date: ${date} 23 | * @since JDK 1.8 24 | */ 25 | @Service(value = "${table.letterEntityName}LogicService") 26 | public class ${table.entityName}LogicService implements I${table.entityName}LogicService { 27 | 28 | @Autowired 29 | private ${table.entityName}Mapper ${table.letterEntityName}Mapper; 30 | 31 | /**可选插入返回主键*/ 32 | @Override 33 | public ${table.keyField.propertyType} insert${table.entityName}(${entityName} entity) { 34 | ${table.keyField.propertyType} ${table.keyField.propertyName} = null; 35 | try { 36 | ${table.letterEntityName}Mapper.insertSelective(entity); 37 | ${table.keyField.propertyName} = entity.get${table.keyField.capitalPropertyName}(); 38 | } catch (Exception e) { 39 | throw new DaoException("数据库异常", e); 40 | } 41 | return ${table.keyField.propertyName}; 42 | } 43 | 44 | /**批量插入*/ 45 | @Override 46 | public void insert${table.entityName}s(List<${entityName}> records) { 47 | try { 48 | ${table.letterEntityName}Mapper.insertRecords(records); 49 | } catch(Exception e) { 50 | throw new DaoException("数据库异常", e); 51 | } 52 | } 53 | 54 | /**条件查询返回匹配的第一条记录*/ 55 | @Override 56 | public ${entityName} query${table.entityName}LimitOne(${entityName} entity) { 57 | try { 58 | return ${table.letterEntityName}Mapper.queryLimitOne(entity); 59 | } catch(Exception e) { 60 | throw new DaoException("数据库异常", e); 61 | } 62 | } 63 | 64 | /**条件查询*/ 65 | @Override 66 | public List<${entityName}> queryByCond(${entityName} entity) { 67 | try { 68 | return ${table.letterEntityName}Mapper.queryByCond(entity); 69 | } catch(Exception e) { 70 | throw new DaoException("数据库异常", e); 71 | } 72 | } 73 | 74 | /**分页查询 若记录为空则对象中的记录数为空列表*/ 75 | @Override 76 | public PageDto<${entityName}> pageQueryByCond(${entityName} entity, int pageNum, int pageSize) { 77 | PageDto<${entityName}> result = null; 78 | try { 79 | Page<${entityName}> page = PageHelper.startPage(pageNum, pageSize) 80 | .doSelectPage(() -> ${table.letterEntityName}Mapper.queryByCond(entity)); 81 | result = new PageDto<>(pageSize, pageNum, page.getResult(), Integer.valueOf(page.getTotal() + "")); 82 | } catch (Exception e) { 83 | throw new DaoException("数据库异常", e); 84 | } 85 | return result == null ? new PageDto<>(pageSize, pageNum, Lists.newArrayListWithCapacity(1) , 0) : result; 86 | } 87 | 88 | /**主键查询 可能返回Null*/ 89 | @Override 90 | public ${entityName} query${table.entityName}By${table.keyField.capitalPropertyName} (${table.keyField.propertyType} ${table.keyField.propertyName}) { 91 | try { 92 | return ${table.letterEntityName}Mapper.queryBy${table.keyField.capitalPropertyName}(${table.keyField.propertyName}); 93 | } catch(Exception e) { 94 | throw new DaoException("数据库异常", e); 95 | } 96 | } 97 | 98 | /**主键批量查询 可能返回空列表*/ 99 | @Override 100 | List<${entityName}> query${table.entityName}By${table.keyField.capitalPropertyName}s (List<${table.keyField.propertyType}> ${table.keyField.propertyName}s) { 101 | try { 102 | return ${table.letterEntityName}Mapper.queryBy${table.keyField.capitalPropertyName}s(${table.keyField.propertyName}s); 103 | } catch(Exception e) { 104 | throw new DaoException("数据库异常", e); 105 | } 106 | } 107 | 108 | /**主键更新*/ 109 | @Override 110 | public boolean update${table.entityName}By${table.keyField.capitalPropertyName} (${entityName} entity) { 111 | try { 112 | return ${table.letterEntityName}Mapper.update${table.entityName}By${table.keyField.capitalPropertyName}(entity) > 0; 113 | } catch(Exception e) { 114 | throw new DaoException("数据库异常", e); 115 | } 116 | } 117 | 118 | /**主键删除*/ 119 | @Override 120 | public boolean delete${table.entityName}By${table.keyField.capitalPropertyName} (${table.keyField.propertyType} ${table.keyField.propertyName}) { 121 | try { 122 | return ${table.letterEntityName}Mapper.delete${table.entityName}By${table.keyField.capitalPropertyName}(${table.keyField.propertyName}) > 0; 123 | } catch(Exception e) { 124 | throw new DaoException("数据库异常", e); 125 | } 126 | } 127 | 128 | } -------------------------------------------------------------------------------- /src/main/resources/mapper.xml.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #if(${enableCache}) 5 | 6 | 7 | #end 8 | 9 | 10 | #foreach($field in ${table.fields}) 11 | #if(${field.primary}) 12 | 13 | #else 14 | 15 | #end 16 | #end 17 | 18 | 19 | ${table.name} 20 | 21 | ## 22 | #foreach($field in ${table.fields}) 23 | #if($velocityCount != 1) 24 | ,${field.name}## 25 | #else 26 | ${field.name}## 27 | #end 28 | #end 29 | 30 | 31 | 32 | #foreach($field in ${table.fields}) 33 | #parseStringType($field) 34 | and ${field.name} = #{${field.propertyName}} 35 | 36 | #end 37 | 38 | 39 | #macro(parseStringType $filed) 40 | #if(${field.propertyType.equals("String")}) 41 | 42 | #else 43 | 44 | #end 45 | #end 46 | 47 | 48 | 49 | insert into 50 | 51 | #foreach($field in ${table.fields}) 52 | #parseStringType($field) 53 | #if($velocityCount != $!{table.fields.size()}) 54 | ${field.name}, 55 | #else 56 | ${field.name} 57 | #end 58 | 59 | #end 60 | 61 | 62 | #foreach($field in ${table.fields}) 63 | #parseStringType($field) 64 | #if($velocityCount != $!{table.fields.size()}) 65 | #{${field.propertyName}}, 66 | #else 67 | #{${field.propertyName}} 68 | #end 69 | 70 | #end 71 | 72 | 73 | 74 | 75 | 76 | insert into 77 | 78 | 79 | 80 | 81 | (## 82 | #foreach($field in ${table.fields}) 83 | #if($velocityCount != $!{table.fields.size()}) 84 | #{${field.propertyName}}, 85 | #else 86 | #{${field.propertyName}} 87 | #end 88 | #end 89 | ) 90 | 91 | 92 | 93 | 94 | 99 | 100 | 101 | 105 | 106 | 107 | 112 | 113 | 114 | 122 | 123 | 124 | 125 | update 126 | 127 | #foreach($field in ${table.fields}) 128 | #parseStringType($field) 129 | #if($velocityCount != $!{table.fields.size()}) 130 | ${field.name} = #{${field.propertyName}}, 131 | #else 132 | ${field.name} = #{${field.propertyName}} 133 | #end 134 | 135 | #end 136 | 137 | ${table.keyField.name} = #{${table.keyField.propertyName}} 138 | 139 | 140 | 141 | 142 | delete from 143 | ${table.keyField.name} = #{${table.keyField.propertyName}} 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/service/out/DataSourceService.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Copyright: Copyright (c) 2016

3 | *

Company: fade

4 | */ 5 | package com.fade.mybatis.service.out;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | import java.text.SimpleDateFormat; 10 | import java.util.Date; 11 | import java.util.List; 12 | import java.util.Map; 13 | import java.util.Objects; 14 | 15 | import org.apache.velocity.VelocityContext; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.stereotype.Service; 20 | 21 | import com.fade.mybatis.config.GeneratorConfig; 22 | import com.fade.mybatis.config.TemplateConfig; 23 | import com.fade.mybatis.enums.NamingStrategyType; 24 | import com.fade.mybatis.enums.TemplateType; 25 | import com.fade.mybatis.model.TableField; 26 | import com.fade.mybatis.model.TableInfo; 27 | import com.fade.mybatis.service.in.DbServiceHelper; 28 | import com.fade.mybatis.service.in.VelocityTemplate; 29 | import com.fade.mybatis.utils.CollectionUtil; 30 | import com.fade.mybatis.utils.StringUtils; 31 | import com.google.common.collect.Maps; 32 | 33 | /** 34 | * Description: 暴露对外的服务
35 | *
dbServiceHelper 需要手动的初始化后赋值
36 | * @author qingquanzhong 37 | * @version 1.0 38 | * @date: 2016-12-18 12:01:14 39 | * @since JDK 1.8 40 | */ 41 | @Service(value = "dataSourceService") 42 | public class DataSourceService { 43 | 44 | private static final Logger logger = LoggerFactory.getLogger(DataSourceService.class); 45 | 46 | private DbServiceHelper dbServiceHelper; 47 | 48 | public DbServiceHelper getDbServiceHelper() { 49 | return dbServiceHelper; 50 | } 51 | 52 | public void setDbServiceHelper(DbServiceHelper dbServiceHelper) { 53 | this.dbServiceHelper = dbServiceHelper; 54 | } 55 | 56 | @Autowired 57 | private VelocityTemplate velocityTemplate; 58 | 59 | /* public static void main(String[] args) { 60 | DataSourceService service = new DataSourceService(); 61 | DataSourceConfig dataSourceConfig = DataSourceConfigBuilder.newInstance().setDbType(DbType.mysql).setHost("127.0.0.1").setPort(3306).setUserName("root").setPassword("fade90,").setDatabaseName("apps").builder(); 62 | service.dbServiceHelper = new DbServiceHelper(dataSourceConfig); 63 | service.velocityTemplate = new VelocityTemplate(); 64 | List tables = service.getTables(""); 65 | if (CollectionUtil.isNotEmpty(tables)) { 66 | tables.forEach(one -> System.out.println(one.getName())); 67 | TableInfo table = tables.get(0);//tables.stream().filter(one -> one.getName().equals("tf_f_user")).findAny().orElse(tables.get(tables.size() - 1)); 68 | List fields = service.getTableCloumns(table.getName(), NamingStrategyType.underline_to_camel, null); 69 | table.setFields(fields); 70 | GeneratorConfig generatorConfig = new GeneratorConfig(); 71 | generatorConfig.setAuthor("卿全忠").setProjectFolder("F://data").setDomainPackage("src/com/fade/entity").setMapperPackage("src/com/fade/dao").setLogicServiceItfPackage("src/com/fade/logicService/itf").setLogicServicePackage("src/com/fade/logicService"); 72 | 73 | service.generateCode(generatorConfig, Lists.newArrayList(table)); 74 | } 75 | } 76 | */ 77 | /*更新模板,没有就新增,有就覆盖*/ 78 | public void updateTemplate() { 79 | 80 | } 81 | 82 | /** 83 | * 获取数据库下所有表 84 | * @return List 表名 85 | */ 86 | public List getTables(String tableName) { 87 | return dbServiceHelper.getTables(tableName); 88 | } 89 | 90 | /** 91 | * 获取指定表结构 92 | * @param tableName 93 | * @return List 94 | */ 95 | public List getTableCloumns(String tableName , NamingStrategyType namingStrategy, String prefix) { 96 | if (StringUtils.isBlank(tableName)) throw new IllegalArgumentException("TableField Name can not be Null or Empty."); 97 | List tableFields = dbServiceHelper.getTableFields(tableName, namingStrategy , prefix); 98 | return tableFields; 99 | } 100 | 101 | 102 | 103 | /** 104 | * 生成代码 105 | *
106 |      * 1.参数初略验证
107 |      * 2.初始上下文信息
108 |      * 3.执行生成
109 |      * 
110 | */ 111 | public void generateCode(GeneratorConfig generatorConfig , List tables ) { 112 | // 参数校验 113 | if (CollectionUtil.isEmpty(tables)) throw new IllegalArgumentException("请选择要操作的表"); 114 | Objects.requireNonNull(generatorConfig, "通用配置信息丢失"); 115 | 116 | //模板配置 117 | final TemplateConfig templateConfig = Objects.isNull(generatorConfig.getTemplateConfig()) ? TemplateConfig.getDefault() : generatorConfig.getTemplateConfig(); 118 | Map contextMap = initContext(generatorConfig, tables); 119 | 120 | contextMap.forEach((name, context) -> { 121 | /**依次生成对应的Entity、xml、Mapper、LogicService*/ 122 | velocityTemplate.mergeVm2File(context, templateConfig.getEntity().getPath(), (String) context.get("entityOutput") ); 123 | 124 | velocityTemplate.mergeVm2File(context, templateConfig.getMapper().getPath(), (String) context.get("xmlOutput") ); 125 | 126 | velocityTemplate.mergeVm2File(context, templateConfig.getDao().getPath(), (String) context.get("mapperOutput") ); 127 | 128 | velocityTemplate.mergeVm2File(context, templateConfig.getServiceItf().getPath(), (String) context.get("serviceItfOutput")); 129 | 130 | velocityTemplate.mergeVm2File(context, templateConfig.getService().getPath(), (String) context.get("serviceOutput") ); 131 | }); 132 | } 133 | 134 | 135 | private Map initContext(GeneratorConfig generatorConfig , List tables) { 136 | logger.info("解析并填充上下文数据....."); 137 | Map contextMap = Maps.newHashMap(); 138 | 139 | /**作者*/ 140 | final String author = generatorConfig.getAuthor(); 141 | /**时间*/ 142 | final String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); 143 | /**是否使用建造者 默认使用*/ 144 | final Boolean builderModel = generatorConfig.getUseBuilderModel(); 145 | final String baseDir = generatorConfig.getProjectFolder(); 146 | /**路径信息*/ 147 | Map packageInfo = Maps.newHashMap(); 148 | packageInfo.put("Entity", generatorConfig.getDomainPackage().replace("/", ".").replace("\\", ".")); 149 | packageInfo.put("Mapper", generatorConfig.getMapperPackage().replace("/", ".").replace("\\", ".")); 150 | packageInfo.put("XmlMapper", generatorConfig.getXmlMapperPackage().replace("/", ".").replace("\\", ".")); 151 | packageInfo.put("LogicServiceItf", generatorConfig.getLogicServiceItfPackage().replace("/", ".").replace("\\", ".")); 152 | packageInfo.put("LogicService", generatorConfig.getLogicServicePackage().replace("/", ".").replace("\\", ".")); 153 | 154 | tables.forEach(table -> { 155 | /**获得列*/ 156 | table.setFields(dbServiceHelper.getTableFields(table.getName(), generatorConfig.getNameStrategy(), generatorConfig.getPrefix())); 157 | table.setEntityName(NamingStrategyType.toCapital(NamingStrategyType.converNaming(table.getCapitalName(), generatorConfig.getNameStrategy(), generatorConfig.getPrefix()))); 158 | VelocityContext ctx = new VelocityContext(); 159 | String entityName = table.getEntityName(); 160 | ctx.put("author",author); 161 | ctx.put("date", date); 162 | ctx.put("simpleBuilderModel", builderModel); 163 | ctx.put("package", packageInfo); 164 | ctx.put("entityName", table.getEntityName() + "Entity"); 165 | 166 | /**输出文件路径信息*/ 167 | ctx.put("entityOutput", String.format(TemplateType.entity_java.getPathTmeplate(), baseDir , generatorConfig.getDomainPackage().replace(".", "/"), entityName)); 168 | ctx.put("xmlOutput", String.format(TemplateType.mapper_xml.getPathTmeplate(), baseDir, generatorConfig.getXmlMapperPackage().replace(".", "/"), entityName)); 169 | ctx.put("mapperOutput", String.format(TemplateType.mapper_java.getPathTmeplate(), baseDir, generatorConfig.getMapperPackage().replace(".", "/"), entityName)); 170 | ctx.put("serviceItfOutput", String.format(TemplateType.service_itf_java.getPathTmeplate(), baseDir, generatorConfig.getLogicServiceItfPackage().replace(".", "/"), entityName)); 171 | ctx.put("serviceOutput", String.format(TemplateType.service_java.getPathTmeplate(), baseDir, generatorConfig.getLogicServicePackage().replace(".", "/"), entityName)); 172 | 173 | /**表结构信息*/ 174 | ctx.put("table", table); 175 | contextMap.put(table.getName(), ctx); 176 | }); 177 | 178 | return contextMap; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.fade.mybatis.controller; 5 | 6 | import java.util.List; 7 | import java.util.Objects; 8 | import java.util.stream.Collectors; 9 | 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.web.bind.annotation.DeleteMapping; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.RequestBody; 18 | import org.springframework.web.bind.annotation.RestController; 19 | 20 | import com.fade.mybatis.config.DataSourceConfig; 21 | import com.fade.mybatis.config.GeneratorConfig; 22 | import com.fade.mybatis.config.builder.DataSourceConfigBuilder; 23 | import com.fade.mybatis.enums.DbType; 24 | import com.fade.mybatis.enums.EncodeType; 25 | import com.fade.mybatis.enums.NamingStrategyType; 26 | import com.fade.mybatis.model.TableInfo; 27 | import com.fade.mybatis.service.in.DbServiceHelper; 28 | import com.fade.mybatis.service.in.LocalDBHelper; 29 | import com.fade.mybatis.service.out.DataSourceService; 30 | import com.fade.mybatis.utils.CollectionUtil; 31 | import com.fade.mybatis.vo.DBConfigVo; 32 | import com.fade.mybatis.vo.GeneratorVo; 33 | import com.fade.mybatis.vo.ResultVo; 34 | import com.google.common.base.Strings; 35 | 36 | /** 37 | * Description: 统一对外入口
38 | * 39 | * @author qingquanzhong 40 | * @version 1.0 41 | * @date: 2016-12-20 12:01:14 42 | * @since JDK 1.8 43 | */ 44 | @RestController 45 | public class HomeController { 46 | 47 | private static final Logger logger = LoggerFactory.getLogger(HomeController.class); 48 | 49 | @Autowired 50 | private DataSourceService dataSourceService; 51 | 52 | /** 53 | * 获取保存的数据库配置信息 54 | */ 55 | @GetMapping("/dbConfig") 56 | public Object getDbConfigs() { 57 | ResultVo result = new ResultVo<>(); 58 | List vos = LocalDBHelper.list(); 59 | return result.setSuccessValue(vos); 60 | } 61 | 62 | /** 63 | * 保存或更新数据库配置 64 | */ 65 | @PostMapping("/dbConfig") 66 | public Object saveDbConfig(@RequestBody DBConfigVo config) { 67 | ResultVo result = new ResultVo<>(); 68 | if (Strings.isNullOrEmpty(config.getId())) { 69 | LocalDBHelper.save(config); 70 | } else { 71 | LocalDBHelper.update(config); 72 | } 73 | return result.setSuccessValue("保存成功"); 74 | } 75 | 76 | @DeleteMapping("/dbConfig/{id}") 77 | public Object removeDbConfig(@PathVariable String id) { 78 | ResultVo result = new ResultVo<>(); 79 | LocalDBHelper.remove(id); 80 | return result.setSuccessValue("删除成功"); 81 | } 82 | 83 | 84 | @GetMapping("/getDbInfo") 85 | public Object getDbName() { 86 | logger.info(".................获取当前连接数据库信息"); 87 | ResultVo result = new ResultVo<>(); 88 | try{ 89 | Objects.requireNonNull(dataSourceService.getDbServiceHelper(), "未初始化数据库连接"); 90 | DbServiceHelper dbHelper = dataSourceService.getDbServiceHelper(); 91 | result.setSuccessValue(dbHelper.getDbInfo()); 92 | } catch (Exception e) { 93 | logger.error("服务异常" + e.getMessage(), e); 94 | result.setFaildMessage(e.getMessage()); 95 | } 96 | return result; 97 | } 98 | 99 | /*** 100 | * 测试连接是否有效 101 | */ 102 | @PostMapping("/checkConnection") 103 | public Object testDbConnection(@RequestBody DBConfigVo configVo) { 104 | ResultVo result = new ResultVo<>(); 105 | try { 106 | Objects.requireNonNull(configVo, "缺少必要参数"); 107 | if (Strings.isNullOrEmpty(configVo.getConnectionName())) throw new IllegalArgumentException("请指定连接名"); 108 | if (Strings.isNullOrEmpty(configVo.getHost())) throw new IllegalArgumentException("请指定连接名或IP"); 109 | if (Objects.isNull(configVo.getPort()) || configVo.getPort().intValue() <=0 ) throw new IllegalArgumentException("数据库端口不合法"); 110 | if (Strings.isNullOrEmpty(configVo.getUserName())) throw new IllegalArgumentException("请指定用户名"); 111 | if (Strings.isNullOrEmpty(configVo.getDatabaseName())) throw new IllegalArgumentException("请指定数据库"); 112 | DbType dbType = DbType.get(configVo.getDbType()); 113 | if (null == dbType) throw new IllegalArgumentException("请指定数据库类型"); 114 | EncodeType encode = EncodeType.get(configVo.getEncode()); 115 | DataSourceConfig config = DataSourceConfigBuilder.newInstance().setDbType(dbType) 116 | .setDatabaseName(configVo.getDatabaseName()) 117 | .setEncodeType(encode != null ? encode : EncodeType.UTF8) 118 | .setHost(configVo.getHost()) 119 | .setPort(configVo.getPort()) 120 | .setUserName(configVo.getUserName()) 121 | .setPassword(configVo.getPassword()).builder(); 122 | DbServiceHelper dbServiceHelper= new DbServiceHelper(config); 123 | dbServiceHelper.checkConection(); 124 | result.setSuccessValue("测试连接成功"); 125 | } catch (Exception e) { 126 | result.setFaildMessage("连接失败" + e.getMessage()); 127 | } 128 | return result; 129 | } 130 | 131 | /** 132 | * 切换数据库配置 133 | * 这里需要重新设置DataSourceConfig对象 134 | */ 135 | @PostMapping("switchDb") 136 | public Object switchDb(@RequestBody DBConfigVo configVo) { 137 | ResultVo result = new ResultVo<>(); 138 | try { 139 | logger.info("...............切换数据库........."); 140 | Objects.requireNonNull(configVo, "缺少必要参数"); 141 | if (Strings.isNullOrEmpty(configVo.getConnectionName())) throw new IllegalArgumentException("请指定连接名"); 142 | if (Strings.isNullOrEmpty(configVo.getHost())) throw new IllegalArgumentException("请指定连接名或IP"); 143 | if (Objects.isNull(configVo.getPort()) || configVo.getPort().intValue() <=0 ) throw new IllegalArgumentException("数据库端口不合法"); 144 | if (Strings.isNullOrEmpty(configVo.getUserName())) throw new IllegalArgumentException("请指定用户名"); 145 | if (Strings.isNullOrEmpty(configVo.getDatabaseName())) throw new IllegalArgumentException("请指定数据库"); 146 | DbType dbType = DbType.get(configVo.getDbType()); 147 | if (null == dbType) throw new IllegalArgumentException("请指定数据库类型"); 148 | EncodeType encode = EncodeType.get(configVo.getEncode()); 149 | DataSourceConfig config = DataSourceConfigBuilder.newInstance().setDbType(dbType) 150 | .setDatabaseName(configVo.getDatabaseName()) 151 | .setEncodeType(encode != null ? encode : EncodeType.UTF8) 152 | .setHost(configVo.getHost()) 153 | .setPort(configVo.getPort()) 154 | .setUserName(configVo.getUserName()) 155 | .setPassword(configVo.getPassword()).builder(); 156 | DbServiceHelper dbServiceHelper= new DbServiceHelper(config); 157 | dataSourceService.setDbServiceHelper(dbServiceHelper); 158 | result.setSuccessValue("切换数据库成功"); 159 | } catch (Exception e) { 160 | logger.error("服务异常" + e.getMessage(), e); 161 | result.setFaildMessage(e.getMessage()); 162 | } 163 | return result; 164 | } 165 | 166 | /** 167 | * 获取指定数据库下的所有表 168 | */ 169 | @GetMapping(value = "list/tables") 170 | public Object getDatabaseTables() { 171 | ResultVo result = new ResultVo<>(); 172 | try { 173 | Objects.requireNonNull(dataSourceService.getDbServiceHelper(), "未初始化数据库连接"); 174 | List tables = dataSourceService.getTables(null); 175 | result.setSuccessValue(tables); 176 | } catch (Exception e) { 177 | logger.error("服务异常" + e.getMessage(), e); 178 | result.setFaildMessage(e.getMessage()); 179 | } 180 | return result; 181 | } 182 | 183 | /** 184 | * 获取表的列信息 185 | */ 186 | @GetMapping("/{tableName}/column") 187 | public Object getTableColumn(@PathVariable String tableName) { 188 | ResultVo result = new ResultVo<>(); 189 | Objects.requireNonNull(dataSourceService.getDbServiceHelper(), "未初始化数据库连接"); 190 | return result.setSuccessValue(dataSourceService.getTableCloumns(tableName, NamingStrategyType.underline_to_camel, null)); 191 | } 192 | 193 | /** 194 | * 根据配置生成想要模板 195 | */ 196 | @PostMapping(value = "/generateCode") 197 | public Object exeAutoGenerate(@RequestBody GeneratorVo generatorVo) { 198 | ResultVo result = new ResultVo<>(); 199 | Objects.requireNonNull(generatorVo, "缺少必要参数"); 200 | if (Strings.isNullOrEmpty(generatorVo.getProjectFolder())) throw new IllegalArgumentException("请指定项目路径"); 201 | if (Strings.isNullOrEmpty(generatorVo.getDomainPackage())) throw new IllegalArgumentException("请指定实体类包名"); 202 | if (Strings.isNullOrEmpty(generatorVo.getMapperPackage())) throw new IllegalArgumentException("请指定Dao包名"); 203 | if (Strings.isNullOrEmpty(generatorVo.getLogicServiceItfPackage())) throw new IllegalArgumentException("请指定逻辑接口包名"); 204 | if (Strings.isNullOrEmpty(generatorVo.getLogicServicePackage())) throw new IllegalArgumentException("请指定逻辑服务包名"); 205 | GeneratorConfig generatorConfig = new GeneratorConfig(); 206 | String author = Strings.isNullOrEmpty(generatorVo.getAuthor()) ? "qingquanzhong@126.com" : generatorVo.getAuthor(); 207 | NamingStrategyType nameStrategy = NamingStrategyType.get(generatorVo.getNameStrategy()); 208 | if (null == nameStrategy) nameStrategy = NamingStrategyType.underline_to_camel; 209 | generatorConfig.setAuthor(author).setProjectFolder(generatorVo.getProjectFolder()) 210 | .setDomainPackage(generatorVo.getDomainPackage()) 211 | .setMapperPackage(generatorVo.getMapperPackage()) 212 | .setLogicServiceItfPackage(generatorVo.getLogicServiceItfPackage()) 213 | .setLogicServicePackage(generatorVo.getLogicServicePackage()) 214 | .setNameStrategy(nameStrategy).setPrefix(NamingStrategyType.toCapital(generatorVo.getPrefix())) 215 | .setUseBuilderModel(null == generatorVo.getUseBuilderModel() ? true : generatorVo.getUseBuilderModel()); 216 | List tables = dataSourceService.getTables(null); 217 | List tableNams = generatorVo.getTableNames(); 218 | if (CollectionUtil.isNotEmpty(tableNams)) { 219 | tables = tables.stream().filter(one -> tableNams.contains(one.getName())).collect(Collectors.toList()); 220 | } 221 | dataSourceService.generateCode(generatorConfig, tables); 222 | return result.setSuccessValue("成功生成代码,保存目录:" + generatorVo.getProjectFolder()); 223 | } 224 | 225 | 226 | } 227 | -------------------------------------------------------------------------------- /src/main/java/com/fade/mybatis/service/in/DbServiceHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

Company: fade

3 | *

Copyright: Copyright (c) 2016

4 | */ 5 | package com.fade.mybatis.service.in;/** 6 | * Created by qingquanzhong on 2016/12/18. 7 | */ 8 | 9 | import java.sql.Connection; 10 | import java.sql.DatabaseMetaData; 11 | import java.sql.DriverManager; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.util.ArrayList; 15 | import java.util.HashMap; 16 | import java.util.List; 17 | import java.util.Map; 18 | import java.util.Properties; 19 | 20 | import javax.annotation.PostConstruct; 21 | import javax.annotation.PreDestroy; 22 | 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | import com.fade.mybatis.config.DataSourceConfig; 27 | import com.fade.mybatis.enums.DbType; 28 | import com.fade.mybatis.enums.NamingStrategyType; 29 | import com.fade.mybatis.model.TableField; 30 | import com.fade.mybatis.model.TableInfo; 31 | import com.fade.mybatis.utils.CloseableUtils; 32 | import com.fade.mybatis.utils.StringUtils; 33 | 34 | /** 35 | * Description: 数据库工具
36 | * 37 | * @author qingquanzhong 38 | * @version 1.0 39 | * @date: 2016-12-18 12:17 40 | * @since JDK 1.8 41 | */ 42 | public class DbServiceHelper { 43 | 44 | private static final Logger log = LoggerFactory.getLogger(DbServiceHelper.class); 45 | 46 | private static final int LOGIN_TIME_OUT = 2; 47 | 48 | private DataSourceConfig config; 49 | 50 | private Connection connection; 51 | 52 | public DbServiceHelper(DataSourceConfig config){ 53 | this.config = config; 54 | } 55 | 56 | /**获取当前连接数据库信息*/ 57 | public Map getDbInfo() { 58 | Map map = new HashMap<>(); 59 | map.put("url", config.getUrl()); 60 | map.put("userName", config.getUserName()); 61 | map.put("password", config.getPassword()); 62 | map.put("dbType", config.getDbType().getDesc()); 63 | map.put("databaseName", config.getDbName()); 64 | return map; 65 | } 66 | 67 | /** 68 | * 获取数据库表结构信息 69 | * @return 表信息 70 | */ 71 | public List getTables(String tableName) { 72 | checkConection(); 73 | List tables = new ArrayList(); 74 | ResultSet resultSet = null; 75 | try{ 76 | log.info("try to get talbes from {} (databases).", connection.getMetaData().getDatabaseProductName()); 77 | DatabaseMetaData metaData = connection.getMetaData(); 78 | // resultSet = metaData.getTables(null, DbType.oracle.equals(config.getDbType()) ? config.getUserName() : config.getDbName(), Strings.isNullOrEmpty(tableName) ? "%" : tableName, new String[]{"TABLE"}); 79 | resultSet = metaData.getTables(config.getDbName() ,null , "%", new String[]{"TABLE"}); 80 | TableInfo table; 81 | while (resultSet.next()) { 82 | table = new TableInfo(resultSet.getString("TABLE_NAME"), resultSet.getString("REMARKS")); 83 | tables.add(table); 84 | } 85 | }catch (Exception e) { 86 | log.error("throw exception when try to get tables from database"); 87 | throw new RuntimeException(e); 88 | }finally { 89 | CloseableUtils.closeQuietly(resultSet); 90 | } 91 | tables.forEach(System.out::println); 92 | return tables; 93 | } 94 | 95 | /** 96 | * 获取表字段结构信息 97 | * @param tableName 98 | * @return List 99 | */ 100 | public List getTableFields( String tableName, NamingStrategyType namingStrategy, String prefix) { 101 | if (StringUtils.isBlank(tableName)) throw new RuntimeException("TableName is Null or Empty."); 102 | checkConection(); 103 | ResultSet resultSet = null, keyRs = null; 104 | String primaryKeyColumnName = null; 105 | List fields = new ArrayList(); 106 | try{ 107 | DatabaseMetaData metaData = connection.getMetaData(); 108 | log.info("try to get {} (table's) cloumn", tableName); 109 | resultSet = metaData.getColumns(config.getDbName(), null , tableName, "%"); 110 | keyRs = metaData.getPrimaryKeys(config.getDbName(), null, tableName); 111 | while(keyRs.next()){ 112 | primaryKeyColumnName = keyRs.getString("COLUMN_NAME"); 113 | } 114 | TableField field; 115 | if (null == namingStrategy) namingStrategy = NamingStrategyType.underline_to_camel; 116 | while (resultSet.next()) { 117 | field = new TableField(); 118 | /**字段名*/ 119 | field.setName(resultSet.getString("COLUMN_NAME")); 120 | /**属性名 驼峰法处理*/ 121 | field.setPropertyName(NamingStrategyType.converNaming(field.getName(), namingStrategy, prefix)); 122 | /**主键处理*/ 123 | if(field.getName().equals(primaryKeyColumnName)) field.setPrimary(Boolean.TRUE); 124 | /**描述*/ 125 | field.setComment(resultSet.getString("REMARKS")); 126 | /**类型*/ 127 | field.setJdbcType(resultSet.getString("TYPE_NAME")); 128 | /**是否允许空*/ 129 | /** 0:'YES'; 1:'NO'; 2:''*/ 130 | field.setNullAble(resultSet.getInt("NULLABLE")!= 1); 131 | /** 默认值*/ 132 | field.setDefaultValue(resultSet.getString("COLUMN_DEF")); 133 | field.setTypeName(resultSet.getString("TYPE_NAME").toLowerCase()); 134 | field.setPropertyType(processPropertyType(field.getTypeName())); 135 | fields.add(field); 136 | } 137 | }catch (SQLException e) { 138 | throw new RuntimeException(e); 139 | }finally { 140 | CloseableUtils.closeQuietly(resultSet); 141 | } 142 | return fields; 143 | } 144 | 145 | //****************************************************************************************************************** 146 | 147 | @PreDestroy 148 | private void destoryConnection() { 149 | CloseableUtils.closeQuietly(this.connection); 150 | } 151 | 152 | /** 153 | * 获取数据库连接 154 | * @author qingquanzhong 155 | */ 156 | @PostConstruct 157 | private void getConnection() { 158 | if (null == config) throw new IllegalArgumentException("DataSourceConfig is Null"); 159 | getConnection0(); 160 | } 161 | 162 | private void getConnection0() { 163 | try { 164 | DriverManager.setLoginTimeout(LOGIN_TIME_OUT); 165 | Class.forName(config.getDriverClass()); 166 | Properties properties = new Properties(); 167 | properties.put("user", config.getUserName()); 168 | properties.put("password", config.getPassword()); 169 | properties.setProperty("remarks", "true"); //设置可以获取remarks信息 170 | if (DbType.mysql.equals(config.getDbType())) { 171 | properties.put("useInformationSchema", "true");//表注释 myslq 172 | }else if (DbType.oracle.equals(config.getDbType())) { 173 | properties.setProperty("remarksReporting","true"); // oracle 174 | } 175 | log.info("try get connection :{}", config.getUrl()); 176 | this.connection = DriverManager.getConnection(config.getUrl(), properties); 177 | }catch (SQLException | ClassNotFoundException exception) { 178 | throw new RuntimeException(exception); 179 | } 180 | } 181 | 182 | /**检查Connection 若连接失效重置连接*/ 183 | public void checkConection() { 184 | try { 185 | if (null == connection || connection.isClosed()) { 186 | getConnection0(); 187 | } 188 | }catch (SQLException e) { 189 | log.error("Connection is not effective"); 190 | throw new RuntimeException("Connection is not effective."); 191 | } 192 | } 193 | 194 | private String processPropertyType(String targetType) { 195 | DbType type = this.config.getDbType(); 196 | if (DbType.mysql.equals(type)) 197 | return processMysqlPropertyType(targetType); 198 | else if (DbType.oracle.equals(type)) 199 | return processOraclePropertyType(targetType); 200 | return null; 201 | } 202 | 203 | /**转换属性类型*/ 204 | private static String processMysqlPropertyType(String targetType) { 205 | if (targetType.contains("char") || targetType.contains("varchar") || targetType.contains("text") || targetType.contains("json")) 206 | return "String"; 207 | else if (targetType.equals("bigint")) 208 | return "Long"; 209 | else if (targetType.contains("int")) 210 | return "Integer"; 211 | /**时间戳是否考虑用Date*/ 212 | else if (targetType.equals("timestamp") || targetType.equals("datetime")) 213 | return "Date";//"Timestamp"; 214 | else if (targetType.equals("date") || targetType.equals("year")) 215 | return "Date"; 216 | else if (targetType.equals("float") || targetType.equals("real")) 217 | return "Float"; 218 | else if (targetType.equals("double")) 219 | return "Double"; 220 | else if (targetType.equals("bit")) 221 | // return "Boolean"; 222 | return "Integer"; 223 | else if (targetType.equals("blob") || targetType.contains("binary")) 224 | return "byte[]"; 225 | else if (targetType.equals("decimal")) 226 | return "BigDecimal"; 227 | return "String"; 228 | } 229 | 230 | private String processOraclePropertyType(String targetType) { 231 | if (targetType.contains("char")) { 232 | return "String"; 233 | } else if (targetType.contains("date") || targetType.contains("timestamp")) { 234 | return "Date"; 235 | } else if (targetType.contains("number")) { 236 | if (targetType.matches("number\\(+\\d{1}+\\)")) { 237 | return "Integer"; 238 | } else if (targetType.matches("number\\(+\\d{2}+\\)")) { 239 | return "Long"; 240 | } 241 | return "Double"; 242 | } else if (targetType.contains("float")) { 243 | return "Float"; 244 | } else if (targetType.contains("blob")) { 245 | return "Object"; 246 | } else if (targetType.contains("raw")) { 247 | return "byte[]"; 248 | } 249 | return "String"; 250 | } 251 | } 252 | -------------------------------------------------------------------------------- /src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | spring boot + mybatis + vue + elementui 6 | 7 | 8 | 115 | 116 | 117 | 118 | 119 | 120 |
121 | 122 |
123 |
124 | 125 | 145 |
146 |
147 | 148 | 149 | 157 | 158 | 159 |
160 | 161 | 162 | 163 | 164 | 165 | 172 | 173 | 174 | 177 | 178 | 179 | 182 | 183 | 184 | 187 | 188 | 189 | 192 | 193 | 194 | 197 | 198 | 199 | 202 | 203 | 204 | 207 | 208 | 209 | 212 | 213 | 214 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 227 | 228 | 229 | 232 | 233 | 234 | 237 | 238 | 239 | 242 | 243 | 244 | 247 | 248 | 249 | 252 | 253 | 254 | 257 | 258 | 259 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 |
329 | 全选(默认当前连接下所有表) 330 |
331 | 332 | {{table.name}}表 333 | 334 |
335 |
336 | 337 | 执行生成 338 | 清空重置 339 | 340 |
341 |
342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 保存连接 379 | 380 | 381 | 测试连接 382 | {{buttonTitle}} 383 | 取消 384 | 385 | 386 | 387 |
388 | 389 |
390 | 391 | 815 | 816 | --------------------------------------------------------------------------------