Commit 40b90936 by bianpeng

修改目录结构

parent 4a417b98
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
</p> </p>
<p align="center"> <p align="center">
<a target="_blank" href="https://search.maven.org/search?q=com.github.flying-cattle"> <a target="_blank" href="https://search.maven.org/search?q=com.gitee.flying-cattle">
<img alt="Maven Central" src="https://img.shields.io/maven-central/v/com.github.flying-cattle/mybatis-dsc-generator.svg"> <img alt="Maven Central" src="https://img.shields.io/maven-central/v/com.gitee.flying-cattle/mybatis-dsc-generator.svg">
</a> </a>
<a target="_blank" href="https://www.apache.org/licenses/LICENSE-2.0.html"> <a target="_blank" href="https://www.apache.org/licenses/LICENSE-2.0.html">
<img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" ></img> <img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" ></img>
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
# mybatis-dsc-generator # mybatis-dsc-generator
完美集成lombok,swagger的代码生成工具,让你不再为繁琐的注释和简单的接口实现而烦恼:entity集成,格式校验,swagger; dao自动加@ mapper,service自动注释和依赖; 控制器实现单表的增副改查,并集成swagger实现api文档。如果有缘看见,期望得到你的star,very thx. 完美集成lombok,swagger的代码生成工具,让你不再为繁琐的注释和简单的接口实现而烦恼:entity集成,格式校验,swagger; dao自动加@ mapper,service自动注释和依赖; 控制器实现单表的增副改查,并集成swagger实现api文档。如果有缘看见,期望得到你的star,very thx.
# 源码地址 # 源码地址
- GitHub:https://github.com/flying-cattle/mybatis-dsc-generator - gitee:https://gitee.com/flying-cattle/mybatis-dsc-generator
- 码云:https://gitee.com/flying-cattle/mybatis-dsc-generator - 码云:https://gitee.com/flying-cattle/mybatis-dsc-generator
# MAVEN地址 # MAVEN地址
2.1.0版本是未集成Mybatis-plus版本——源码分支master 2.1.0版本是未集成Mybatis-plus版本——源码分支master
``` xml ``` xml
<dependency> <dependency>
<groupId>com.github.flying-cattle</groupId> <groupId>com.gitee.flying-cattle</groupId>
<artifactId>mybatis-dsc-generator</artifactId> <artifactId>mybatis-dsc-generator</artifactId>
<version>2.1.0.RELEASE</version> <version>2.1.0.RELEASE</version>
</dependency> </dependency>
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
3.0.0后的版本是集成了Mybatis-plus版本——源码分支mybatisPlus 3.0.0后的版本是集成了Mybatis-plus版本——源码分支mybatisPlus
``` xml ``` xml
<dependency> <dependency>
<groupId>com.github.flying-cattle</groupId> <groupId>com.gitee.flying-cattle</groupId>
<artifactId>mybatis-dsc-generator</artifactId> <artifactId>mybatis-dsc-generator</artifactId>
<version>3.0.6.RELEASE</version> <version>3.0.6.RELEASE</version>
</dependency> </dependency>
...@@ -59,7 +59,7 @@ CREATE TABLE `user` ( ...@@ -59,7 +59,7 @@ CREATE TABLE `user` (
要求必须有表注释,要求必须有主键为id,所有字段必须有注释(便于生成java注释swagger等)。 要求必须有表注释,要求必须有主键为id,所有字段必须有注释(便于生成java注释swagger等)。
# 生成的实体类 # 生成的实体类
生成方法参考源码中的:https://github.com/flying-cattle/mybatis-dsc-generator/blob/mybatisPlus/src/test/java/com/flying/cattle/mdg/MyGenerator.java 生成方法参考源码中的:https://gitee.com/flying-cattle/mybatis-dsc-generator/blob/mybatisPlus/src/test/java/com/flying/cattle/mdg/MyGenerator.java
# 生成的实体类 # 生成的实体类
``` java ``` java
......
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.github.flying-cattle</groupId> <groupId>com.gitee.flying-cattle</groupId>
<artifactId>mybatis-dsc-generator</artifactId> <artifactId>mybatis-dsc-generator</artifactId>
<version>3.0.7.RELEASE</version> <version>3.0.7.RELEASE</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>mybatis-dsc-generator</name> <name>mybatis-dsc-generator</name>
<description>According to the database, three layers of code are generated automatically.</description> <description>According to the database, three layers of code are generated automatically.</description>
<url>https://github.com/flying-cattle/mybatis-dsc-generator</url> <url>https://gitee.com/flying-cattle/mybatis-dsc-generator</url>
<!-- 证书 --> <!-- 证书 -->
<licenses> <licenses>
<license> <license>
...@@ -27,9 +27,10 @@ ...@@ -27,9 +27,10 @@
</developer> </developer>
</developers> </developers>
<scm> <scm>
<connection>scm:git:git@github.com:flying-cattle/mybatis-dsc-generator.git</connection> <connection>scm:git:git@gitee.com:flying-cattle/mybatis-dsc-generator.git</connection>
<developerConnection>scm:git:git@github.com:flying-cattle/mybatis-dsc-generator.git</developerConnection> <developerConnection>scm:git:git@gitee.com:flying-cattle/mybatis-dsc-generator.git</developerConnection>
<url>git@github.com:flying-cattle/mybatis-dsc-generator.git</url> <url>git@gitee.com:flying-cattle/mybatis-dsc-generator.git</url>
<tag>HEAD</tag>
</scm> </scm>
<properties> <properties>
...@@ -60,7 +61,7 @@ ...@@ -60,7 +61,7 @@
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version> <version>${mysql-connector-java.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.freemarker</groupId> <groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId> <artifactId>freemarker</artifactId>
...@@ -148,6 +149,17 @@ ...@@ -148,6 +149,17 @@
<encoding>${project.build.sourceEncoding}</encoding> <encoding>${project.build.sourceEncoding}</encoding>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<tagNameFormat>v@{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
<indentSize>4</indentSize>
<useEditMode>true</useEditMode>
<localCheckout>true</localCheckout>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.flying.cattle.mdg.aid * @Package: com.gitee.flying.cattle.mdg.aid
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.aid; package com.gitee.flying.cattle.mdg.aid;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 用户服务层</P> * <p>说明: 用户服务层</P>
* @version: V1.0 * @version: V1.0
* @author: flying.cattle * @author: flying.cattle
*/ */
public class Const { public class Const {
/********************** 响应 ****************************/ /********************** 响应 ****************************/
public static final String CODE_SUCCESS = "200"; // 成功 public static final String CODE_SUCCESS = "200"; // 成功
public static final String CODE_FAILED = "0"; // 失败 public static final String CODE_FAILED = "0"; // 失败
public static final String OPERATE_SUCCESS = "success"; // 成功 public static final String OPERATE_SUCCESS = "success"; // 成功
public static final String OPERATE_FAILED = "failed"; // 失败 public static final String OPERATE_FAILED = "failed"; // 失败
public static final String HANDLE_PATH = ".*/((index.html)|(index.jsp)).*"; public static final String HANDLE_PATH = ".*/((index.html)|(index.jsp)).*";
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.flying.cattle.mdg.aid * @Package: com.gitee.flying.cattle.mdg.aid
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.aid; package com.gitee.flying.cattle.mdg.aid;
import java.io.Serializable; import java.io.Serializable;
import java.net.ConnectException; import java.net.ConnectException;
import java.sql.SQLException; import java.sql.SQLException;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 用户服务层</P> * <p>说明: 用户服务层</P>
* @version: V1.0 * @version: V1.0
* @author: flying-cattle * @author: flying-cattle
*/ */
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class JsonResult<T> implements Serializable{ public class JsonResult<T> implements Serializable{
private static final long serialVersionUID = 1071681926787951549L; private static final long serialVersionUID = 1071681926787951549L;
/** /**
*<p>状态码</p> *<p>状态码</p>
*/ */
private String code; private String code;
/** /**
* <p>业务码</p> * <p>业务码</p>
*/ */
private String operate; private String operate;
/** /**
*<p> 状态说明</p> *<p> 状态说明</p>
*/ */
private String message; private String message;
/** /**
* <p>返回数据</p> * <p>返回数据</p>
*/ */
private T data; private T data;
/** /**
* <p>返回成功,有数据</p> * <p>返回成功,有数据</p>
* @param message 操作说明 * @param message 操作说明
* @param data 对象 * @param data 对象
* @return JsonResult * @return JsonResult
*/ */
public JsonResult<T> success(String message,T data) { public JsonResult<T> success(String message,T data) {
this.setCode(Const.CODE_SUCCESS); this.setCode(Const.CODE_SUCCESS);
this.setOperate(Const.OPERATE_SUCCESS); this.setOperate(Const.OPERATE_SUCCESS);
this.setMessage(message); this.setMessage(message);
this.setData(data); this.setData(data);
return this; return this;
} }
/** /**
* <p>返回成功,有数据</p> * <p>返回成功,有数据</p>
* @param data 对象 * @param data 对象
* @return JsonResult * @return JsonResult
*/ */
public JsonResult<T> success(T data) { public JsonResult<T> success(T data) {
this.setCode(Const.CODE_SUCCESS); this.setCode(Const.CODE_SUCCESS);
this.setOperate(Const.OPERATE_SUCCESS); this.setOperate(Const.OPERATE_SUCCESS);
this.setMessage("操作成功"); this.setMessage("操作成功");
this.setData(data); this.setData(data);
return this; return this;
} }
/** /**
* <p>返回成功,无数据</p> * <p>返回成功,无数据</p>
* @param message 操作说明 * @param message 操作说明
* @return JsonResult * @return JsonResult
*/ */
public JsonResult<T> success(String message) { public JsonResult<T> success(String message) {
this.setCode(Const.CODE_SUCCESS); this.setCode(Const.CODE_SUCCESS);
this.setOperate(Const.OPERATE_SUCCESS); this.setOperate(Const.OPERATE_SUCCESS);
this.setMessage(message); this.setMessage(message);
this.setData(null); this.setData(null);
return this; return this;
} }
/** /**
* <p>返回失败,无数据</p> * <p>返回失败,无数据</p>
* @param message 消息 * @param message 消息
* @return JsonResult * @return JsonResult
*/ */
public JsonResult<T> error(String message) { public JsonResult<T> error(String message) {
this.setCode(Const.CODE_FAILED); this.setCode(Const.CODE_FAILED);
this.setOperate(Const.OPERATE_FAILED); this.setOperate(Const.OPERATE_FAILED);
this.setMessage(message); this.setMessage(message);
this.setData(null); this.setData(null);
return this; return this;
} }
/** /**
* <p>返回失败,有数据</p> * <p>返回失败,有数据</p>
* @param message 消息 * @param message 消息
* @param data 对象 * @param data 对象
* @return JsonResult * @return JsonResult
*/ */
public JsonResult<T> error(String message,T data) { public JsonResult<T> error(String message,T data) {
this.setCode(Const.CODE_FAILED); this.setCode(Const.CODE_FAILED);
this.setOperate(Const.OPERATE_FAILED); this.setOperate(Const.OPERATE_FAILED);
this.setMessage(message); this.setMessage(message);
this.setData(data); this.setData(data);
return this; return this;
} }
public JsonResult(Throwable throwable) { public JsonResult(Throwable throwable) {
this.operate=Const.OPERATE_FAILED; this.operate=Const.OPERATE_FAILED;
if(throwable instanceof NullPointerException){ if(throwable instanceof NullPointerException){
this.code= "1001"; this.code= "1001";
this.message="空指针:"+throwable; this.message="空指针:"+throwable;
}else if(throwable instanceof ClassCastException ){ }else if(throwable instanceof ClassCastException ){
this.code= "1002"; this.code= "1002";
this.message="类型强制转换异常:"+throwable; this.message="类型强制转换异常:"+throwable;
}else if(throwable instanceof ConnectException){ }else if(throwable instanceof ConnectException){
this.code= "1003"; this.code= "1003";
this.message="链接失败:"+throwable; this.message="链接失败:"+throwable;
}else if(throwable instanceof IllegalArgumentException ){ }else if(throwable instanceof IllegalArgumentException ){
this.code= "1004"; this.code= "1004";
this.message="传递非法参数异常:"+throwable; this.message="传递非法参数异常:"+throwable;
}else if(throwable instanceof NumberFormatException){ }else if(throwable instanceof NumberFormatException){
this.code= "1005"; this.code= "1005";
this.message="数字格式异常:"+throwable; this.message="数字格式异常:"+throwable;
}else if(throwable instanceof IndexOutOfBoundsException){ }else if(throwable instanceof IndexOutOfBoundsException){
this.code= "1006"; this.code= "1006";
this.message="下标越界异常:"+throwable; this.message="下标越界异常:"+throwable;
}else if(throwable instanceof SecurityException){ }else if(throwable instanceof SecurityException){
this.code= "1007"; this.code= "1007";
this.message="安全异常:"+throwable; this.message="安全异常:"+throwable;
}else if(throwable instanceof SQLException){ }else if(throwable instanceof SQLException){
this.code= "1008"; this.code= "1008";
this.message="数据库异常:"+throwable; this.message="数据库异常:"+throwable;
}else if(throwable instanceof ArithmeticException){ }else if(throwable instanceof ArithmeticException){
this.code= "1009"; this.code= "1009";
this.message="算术运算异常:"+throwable; this.message="算术运算异常:"+throwable;
}else if(throwable instanceof RuntimeException){ }else if(throwable instanceof RuntimeException){
this.code= "1010"; this.code= "1010";
this.message="运行时异常:"+throwable; this.message="运行时异常:"+throwable;
}else if(throwable instanceof Exception){ }else if(throwable instanceof Exception){
this.code= "9999"; this.code= "9999";
this.message="未知异常"+throwable; this.message="未知异常"+throwable;
} }
} }
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.flying.cattle.mdg.aid * @Package: com.gitee.flying.cattle.mdg.aid
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.aid; package com.gitee.flying.cattle.mdg.aid;
import java.io.Serializable; import java.io.Serializable;
import lombok.Data; import lombok.Data;
/** /**
* app分页组件 * app分页组件
* @author bianP * @author bianP
* @version $Id: AppPage.java, v 0.1 2018年06月20日 下午2:31:23 * @version $Id: AppPage.java, v 0.1 2018年06月20日 下午2:31:23
*/ */
@Data @Data
public class PageParam<T> implements Serializable{ public class PageParam<T> implements Serializable{
private static final long serialVersionUID = -7248374800878487522L; private static final long serialVersionUID = -7248374800878487522L;
/** /**
* <p>当前页</p> * <p>当前页</p>
*/ */
private int pageNum=1; private int pageNum=1;
/** /**
* <p>每页记录数</p> * <p>每页记录数</p>
*/ */
private int pageSize=10; private int pageSize=10;
/** /**
* <p>分页外的其它参数</p> * <p>分页外的其它参数</p>
*/ */
private T param; private T param;
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.convert * @Package: com.gitee.mybatis.fl.convert
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.convert; package com.gitee.flying.cattle.mdg.convert;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 数据库时间类型 到 实体类时间类型 对应策略</P> * <p>说明: 数据库时间类型 到 实体类时间类型 对应策略</P>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
public enum DateType { public enum DateType {
/** /**
* *
* <p>只使用 java.util.date 代替</p> * <p>只使用 java.util.date 代替</p>
*/ */
ONLY_DATE, ONLY_DATE,
/** /**
* <p>使用 java.sql 包下的</p> * <p>使用 java.sql 包下的</p>
*/ */
SQL_PACK, SQL_PACK,
/** /**
* <p>使用 java.time 包下的</p> * <p>使用 java.time 包下的</p>
* <p>java8 新的时间类型</p> * <p>java8 新的时间类型</p>
*/ */
TIME_PACK TIME_PACK
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* *
* @Package: com.github.mybatis.fl.convert * @Package: com.gitee.mybatis.fl.convert
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.convert; package com.gitee.flying.cattle.mdg.convert;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明:表字段类型</p> * <p>说明:表字段类型</p>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
public enum DbColumnType implements IColumnType { public enum DbColumnType implements IColumnType {
// 基本类型 // 基本类型
BASE_BYTE("byte", null), BASE_BYTE("byte", null),
BASE_SHORT("short", null), BASE_SHORT("short", null),
BASE_CHAR("char", null), BASE_CHAR("char", null),
BASE_INT("int", null), BASE_INT("int", null),
BASE_LONG("long", null), BASE_LONG("long", null),
BASE_FLOAT("float", null), BASE_FLOAT("float", null),
BASE_DOUBLE("double", null), BASE_DOUBLE("double", null),
BASE_BOOLEAN("boolean", null), BASE_BOOLEAN("boolean", null),
// 包装类型 // 包装类型
BYTE("Byte", null), BYTE("Byte", null),
SHORT("Short", null), SHORT("Short", null),
CHARACTER("Character", null), CHARACTER("Character", null),
INTEGER("Integer", null), INTEGER("Integer", null),
LONG("Long", null), LONG("Long", null),
FLOAT("Float", null), FLOAT("Float", null),
DOUBLE("Double", null), DOUBLE("Double", null),
BOOLEAN("Boolean", null), BOOLEAN("Boolean", null),
STRING("String", null), STRING("String", null),
// sql 包下数据类型 // sql 包下数据类型
DATE_SQL("Date", "java.sql.Date"), DATE_SQL("Date", "java.sql.Date"),
TIME("Time", "java.sql.Time"), TIME("Time", "java.sql.Time"),
TIMESTAMP("Timestamp", "java.sql.Timestamp"), TIMESTAMP("Timestamp", "java.sql.Timestamp"),
BLOB("Blob", "java.sql.Blob"), BLOB("Blob", "java.sql.Blob"),
CLOB("Clob", "java.sql.Clob"), CLOB("Clob", "java.sql.Clob"),
// java8 新时间类型 // java8 新时间类型
LOCAL_DATE("LocalDate", "java.time.LocalDate"), LOCAL_DATE("LocalDate", "java.time.LocalDate"),
LOCAL_TIME("LocalTime", "java.time.LocalTime"), LOCAL_TIME("LocalTime", "java.time.LocalTime"),
YEAR("Year", "java.time.Year"), YEAR("Year", "java.time.Year"),
YEAR_MONTH("YearMonth", "java.time.YearMonth"), YEAR_MONTH("YearMonth", "java.time.YearMonth"),
LOCAL_DATE_TIME("LocalDateTime", "java.time.LocalDateTime"), LOCAL_DATE_TIME("LocalDateTime", "java.time.LocalDateTime"),
// 其他杂类 // 其他杂类
BYTE_ARRAY("byte[]", null), BYTE_ARRAY("byte[]", null),
OBJECT("Object", null), OBJECT("Object", null),
DATE("Date", "java.util.Date"), DATE("Date", "java.util.Date"),
BIG_INTEGER("BigInteger", "java.math.BigInteger"), BIG_INTEGER("BigInteger", "java.math.BigInteger"),
BIG_DECIMAL("BigDecimal", "java.math.BigDecimal"); BIG_DECIMAL("BigDecimal", "java.math.BigDecimal");
/** /**
* <p>类型</p> * <p>类型</p>
*/ */
private final String type; private final String type;
/** /**
* <p>包路径</p> * <p>包路径</p>
*/ */
private final String pkg; private final String pkg;
DbColumnType(final String type, final String pkg) { DbColumnType(final String type, final String pkg) {
this.type = type; this.type = type;
this.pkg = pkg; this.pkg = pkg;
} }
@Override @Override
public String getType() { public String getType() {
return type; return type;
} }
@Override @Override
public String getPkg() { public String getPkg() {
return pkg; return pkg;
} }
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* <p> * <p>
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* @Package: com.github.mybatis.fl.convert * @Package: com.gitee.mybatis.fl.convert
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:09:35 * @date: 2019年4月9日 下午8:09:35
*/ */
package com.github.flying.cattle.mdg.convert; package com.gitee.flying.cattle.mdg.convert;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 获取实体类字段属性类信息接口</p> * <p>说明: 获取实体类字段属性类信息接口</p>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
public interface IColumnType { public interface IColumnType {
/** /**
* <p>获取字段类型</p> * <p>获取字段类型</p>
* *
* @return 字段类型 * @return 字段类型
*/ */
String getType(); String getType();
/** /**
* <p> 获取字段类型完整名</p> * <p> 获取字段类型完整名</p>
* *
* @return 字段类型完整名 * @return 字段类型完整名
*/ */
String getPkg(); String getPkg();
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* <p> * <p>
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* @Package: com.github.mybatis.fl.convert * @Package: com.gitee.mybatis.fl.convert
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:06:16 * @date: 2019年4月9日 下午8:06:16
*/ */
package com.github.flying.cattle.mdg.convert; package com.gitee.flying.cattle.mdg.convert;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 该类的功能描述</p> * <p>说明: 该类的功能描述</p>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
public interface ITypeConvert { public interface ITypeConvert {
/** /**
* <p>说明:执行类型转换</p> * <p>说明:执行类型转换</p>
* @param dateType 时间类型 * @param dateType 时间类型
* @param fieldType 字段类型 * @param fieldType 字段类型
* @return ignore * @return ignore
*/ */
IColumnType processTypeConvert(DateType dateType , String fieldType); IColumnType processTypeConvert(DateType dateType , String fieldType);
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* *
* @Package: com.github.mybatis.fl.convert * @Package: com.gitee.mybatis.fl.convert
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:13:13 * @date: 2019年4月9日 下午8:13:13
*/ */
package com.github.flying.cattle.mdg.convert; package com.gitee.flying.cattle.mdg.convert;
import com.github.flying.cattle.mdg.convert.ITypeConvert; import com.gitee.flying.cattle.mdg.convert.ITypeConvert;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明:MYSQL 数据库字段类型转换</p> * <p>说明:MYSQL 数据库字段类型转换</p>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
public class MySqlTypeConvert implements ITypeConvert { public class MySqlTypeConvert implements ITypeConvert {
@Override @Override
public IColumnType processTypeConvert(DateType dateType, String fieldType) { public IColumnType processTypeConvert(DateType dateType, String fieldType) {
String t = fieldType.toLowerCase(); String t = fieldType.toLowerCase();
if (t.contains("char")) { if (t.contains("char")) {
return DbColumnType.STRING; return DbColumnType.STRING;
} else if (t.contains("bigint")) { } else if (t.contains("bigint")) {
return DbColumnType.LONG; return DbColumnType.LONG;
} else if (t.contains("tinyint(1)")) { } else if (t.contains("tinyint(1)")) {
return DbColumnType.BOOLEAN; return DbColumnType.BOOLEAN;
} else if (t.contains("int")) { } else if (t.contains("int")) {
return DbColumnType.INTEGER; return DbColumnType.INTEGER;
} else if (t.contains("text")) { } else if (t.contains("text")) {
return DbColumnType.STRING; return DbColumnType.STRING;
} else if (t.contains("bit")) { } else if (t.contains("bit")) {
return DbColumnType.BOOLEAN; return DbColumnType.BOOLEAN;
} else if (t.contains("decimal")) { } else if (t.contains("decimal")) {
return DbColumnType.BIG_DECIMAL; return DbColumnType.BIG_DECIMAL;
} else if (t.contains("clob")) { } else if (t.contains("clob")) {
return DbColumnType.CLOB; return DbColumnType.CLOB;
} else if (t.contains("blob")) { } else if (t.contains("blob")) {
return DbColumnType.BLOB; return DbColumnType.BLOB;
} else if (t.contains("binary")) { } else if (t.contains("binary")) {
return DbColumnType.BYTE_ARRAY; return DbColumnType.BYTE_ARRAY;
} else if (t.contains("float")) { } else if (t.contains("float")) {
return DbColumnType.FLOAT; return DbColumnType.FLOAT;
} else if (t.contains("double")) { } else if (t.contains("double")) {
return DbColumnType.DOUBLE; return DbColumnType.DOUBLE;
} else if (t.contains("json") || t.contains("enum")) { } else if (t.contains("json") || t.contains("enum")) {
return DbColumnType.STRING; return DbColumnType.STRING;
} else if (t.contains("date") || t.contains("time") || t.contains("year")) { } else if (t.contains("date") || t.contains("time") || t.contains("year")) {
switch (dateType) { switch (dateType) {
case ONLY_DATE: case ONLY_DATE:
return DbColumnType.DATE; return DbColumnType.DATE;
case SQL_PACK: case SQL_PACK:
switch (t) { switch (t) {
case "date": case "date":
return DbColumnType.DATE_SQL; return DbColumnType.DATE_SQL;
case "time": case "time":
return DbColumnType.TIME; return DbColumnType.TIME;
case "year": case "year":
return DbColumnType.DATE_SQL; return DbColumnType.DATE_SQL;
default: default:
return DbColumnType.TIMESTAMP; return DbColumnType.TIMESTAMP;
} }
case TIME_PACK: case TIME_PACK:
switch (t) { switch (t) {
case "date": case "date":
return DbColumnType.LOCAL_DATE; return DbColumnType.LOCAL_DATE;
case "time": case "time":
return DbColumnType.LOCAL_TIME; return DbColumnType.LOCAL_TIME;
case "year": case "year":
return DbColumnType.YEAR; return DbColumnType.YEAR;
default: default:
return DbColumnType.LOCAL_DATE_TIME; return DbColumnType.LOCAL_DATE_TIME;
} }
} }
} }
return DbColumnType.STRING; return DbColumnType.STRING;
} }
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.entity * @Package: com.gitee.mybatis.fl.entity
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.entity; package com.gitee.flying.cattle.mdg.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 自动生成需要的基本信息</P> * <p>说明: 自动生成需要的基本信息</P>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class BasisInfo implements Serializable{ public class BasisInfo implements Serializable{
private static final long serialVersionUID = 123123L; private static final long serialVersionUID = 123123L;
private String project; private String project;
private String author; private String author;
private String version; private String version;
private String dbUrl; private String dbUrl;
private String dbName; private String dbName;
private String dbPassword; private String dbPassword;
private String database; private String database;
private String table; private String table;
private String entityName; private String entityName;
private String objectName; private String objectName;
private String entityComment; private String entityComment;
private String createTime; private String createTime;
private String agile; private String agile;
private String entityUrl; private String entityUrl;
private String daoUrl; private String daoUrl;
private String mapperUrl; private String mapperUrl;
private String serviceUrl; private String serviceUrl;
private String serviceImplUrl; private String serviceImplUrl;
private String abstractControllerUrl; private String abstractControllerUrl;
private String controllerUrl; private String controllerUrl;
private String swaggerConfigUrl; private String swaggerConfigUrl;
private String idType; private String idType;
private String idJdbcType; private String idJdbcType;
private List<PropertyInfo> cis; private List<PropertyInfo> cis;
private String isSwagger="true"; private String isSwagger="true";
private Set<String> pkgs = new HashSet<String>(); private Set<String> pkgs = new HashSet<String>();
public BasisInfo(String project, String author, String version, String dbUrl, String dbName, String dbPassword, public BasisInfo(String project, String author, String version, String dbUrl, String dbName, String dbPassword,
String database, String createTime, String agile, String entityUrl, String daoUrl, String mapperUrl, String database, String createTime, String agile, String entityUrl, String daoUrl, String mapperUrl,
String serviceUrl, String serviceImplUrl, String controllerUrl,String isSwagger) { String serviceUrl, String serviceImplUrl, String controllerUrl,String isSwagger) {
super(); super();
this.project = project; this.project = project;
this.author = author; this.author = author;
this.version = version; this.version = version;
this.dbUrl = dbUrl; this.dbUrl = dbUrl;
this.dbName = dbName; this.dbName = dbName;
this.dbPassword = dbPassword; this.dbPassword = dbPassword;
this.database = database; this.database = database;
this.createTime = createTime; this.createTime = createTime;
this.agile = agile; this.agile = agile;
this.entityUrl = entityUrl; this.entityUrl = entityUrl;
this.daoUrl = daoUrl; this.daoUrl = daoUrl;
this.mapperUrl = mapperUrl; this.mapperUrl = mapperUrl;
this.serviceUrl = serviceUrl; this.serviceUrl = serviceUrl;
this.serviceImplUrl = serviceImplUrl; this.serviceImplUrl = serviceImplUrl;
this.controllerUrl = controllerUrl; this.controllerUrl = controllerUrl;
this.abstractControllerUrl = controllerUrl.substring(0, controllerUrl.lastIndexOf("."))+".aid"; this.abstractControllerUrl = controllerUrl.substring(0, controllerUrl.lastIndexOf("."))+".aid";
this.swaggerConfigUrl=controllerUrl.substring(0, controllerUrl.lastIndexOf("."))+".config"; this.swaggerConfigUrl=controllerUrl.substring(0, controllerUrl.lastIndexOf("."))+".config";
this.isSwagger=isSwagger; this.isSwagger=isSwagger;
} }
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.entity * @Package: com.gitee.mybatis.fl.entity
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.entity; package com.gitee.flying.cattle.mdg.entity;
import java.io.Serializable; import java.io.Serializable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 自动生成文件路径</P> * <p>说明: 自动生成文件路径</P>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class GeneratorFileUrl implements Serializable{ public class GeneratorFileUrl implements Serializable{
private static final long serialVersionUID = 123125L; private static final long serialVersionUID = 123125L;
private String entityUrl; private String entityUrl;
private String daoUrl; private String daoUrl;
private String mapperUrl; private String mapperUrl;
private String serviceUrl; private String serviceUrl;
private String serviceImplUrl; private String serviceImplUrl;
private String controllerUrl; private String controllerUrl;
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.entity * @Package: com.gitee.mybatis.fl.entity
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.entity; package com.gitee.flying.cattle.mdg.entity;
import java.io.Serializable; import java.io.Serializable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 获取到数据库的信息</P> * <p>说明: 获取到数据库的信息</P>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class PropertyInfo implements Serializable{ public class PropertyInfo implements Serializable{
private static final long serialVersionUID = 123124L; private static final long serialVersionUID = 123124L;
private String column; private String column;
private String jdbcType; private String jdbcType;
private String comment; private String comment;
private String property; private String property;
private String javaType; private String javaType;
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.entity * @Package: com.gitee.mybatis.fl.entity
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.entity; package com.gitee.flying.cattle.mdg.entity;
import java.io.Serializable; import java.io.Serializable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 返回结果json对象</P> * <p>说明: 返回结果json对象</P>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class ResultJson implements Serializable{ public class ResultJson implements Serializable{
private static final long serialVersionUID = 123126L; private static final long serialVersionUID = 123126L;
private Integer code; private Integer code;
private String message; private String message;
private Object data; private Object data;
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.util * @Package: com.gitee.mybatis.fl.util
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.util; package com.gitee.flying.cattle.mdg.util;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.github.flying.cattle.mdg.entity.BasisInfo; import com.gitee.flying.cattle.mdg.entity.BasisInfo;
import com.github.flying.cattle.mdg.entity.PropertyInfo; import com.gitee.flying.cattle.mdg.entity.PropertyInfo;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 链接数据库并获取表信息</P> * <p>说明: 链接数据库并获取表信息</P>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
public class EntityInfoUtil { public class EntityInfoUtil {
public static BasisInfo getInfo(BasisInfo bi) throws SQLException { public static BasisInfo getInfo(BasisInfo bi) throws SQLException {
List<PropertyInfo> columns= new ArrayList<PropertyInfo>(); List<PropertyInfo> columns= new ArrayList<PropertyInfo>();
// 创建连接 // 创建连接
Connection con = null; Connection con = null;
PreparedStatement pstemt = null; PreparedStatement pstemt = null;
ResultSet rs = null; ResultSet rs = null;
//sql //sql
String sql="select column_name,data_type,column_comment from information_schema.columns where table_schema='"+bi.getDatabase()+"' and table_name='"+bi.getTable()+"'"; String sql="select column_name,data_type,column_comment from information_schema.columns where table_schema='"+bi.getDatabase()+"' and table_name='"+bi.getTable()+"'";
try { try {
con = DriverManager.getConnection(bi.getDbUrl(), bi.getDbName(), bi.getDbPassword()); con = DriverManager.getConnection(bi.getDbUrl(), bi.getDbName(), bi.getDbPassword());
pstemt = con.prepareStatement(sql); pstemt = con.prepareStatement(sql);
rs = pstemt.executeQuery(); rs = pstemt.executeQuery();
while (rs.next()) { while (rs.next()) {
String column = rs.getString(1); String column = rs.getString(1);
String jdbcType = rs.getString(2); String jdbcType = rs.getString(2);
String comment = rs.getString(3); String comment = rs.getString(3);
PropertyInfo ci=new PropertyInfo(); PropertyInfo ci=new PropertyInfo();
ci.setColumn(column); ci.setColumn(column);
if (jdbcType.equalsIgnoreCase("int")) { if (jdbcType.equalsIgnoreCase("int")) {
ci.setJdbcType("Integer"); ci.setJdbcType("Integer");
}else if (jdbcType.equalsIgnoreCase("datetime")) { }else if (jdbcType.equalsIgnoreCase("datetime")) {
ci.setJdbcType("timestamp"); ci.setJdbcType("timestamp");
}else { }else {
ci.setJdbcType(jdbcType); ci.setJdbcType(jdbcType);
} }
ci.setComment(comment); ci.setComment(comment);
ci.setProperty(MySqlToJavaUtil.changeToJavaFiled(column)); ci.setProperty(MySqlToJavaUtil.changeToJavaFiled(column));
ci.setJavaType(MySqlToJavaUtil.jdbcTypeToJavaType(jdbcType)); ci.setJavaType(MySqlToJavaUtil.jdbcTypeToJavaType(jdbcType));
//设置注解类型 //设置注解类型
if (column.equalsIgnoreCase("id")) { if (column.equalsIgnoreCase("id")) {
bi.setIdType(ci.getJavaType()); bi.setIdType(ci.getJavaType());
bi.setIdJdbcType(ci.getJdbcType()); bi.setIdJdbcType(ci.getJdbcType());
} }
columns.add(ci); columns.add(ci);
//添加包路径 //添加包路径
Set<String> pkgs= bi.getPkgs(); Set<String> pkgs= bi.getPkgs();
pkgs.add(MySqlToJavaUtil.jdbcTypeToJavaTypePck(jdbcType)); pkgs.add(MySqlToJavaUtil.jdbcTypeToJavaTypePck(jdbcType));
bi.setPkgs(pkgs); bi.setPkgs(pkgs);
} }
bi.setCis(columns); bi.setCis(columns);
// 完成后关闭 // 完成后关闭
rs.close(); rs.close();
pstemt.close(); pstemt.close();
con.close(); con.close();
if (null==columns||columns.size()==0) { if (null==columns||columns.size()==0) {
throw new RuntimeException("未能读取到表或表中的字段。请检查链接url,数据库账户,数据库密码,查询的数据名、是否正确。"); throw new RuntimeException("未能读取到表或表中的字段。请检查链接url,数据库账户,数据库密码,查询的数据名、是否正确。");
} }
return bi; return bi;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("自动生成实体类错误:"+e.getMessage()); throw new RuntimeException("自动生成实体类错误:"+e.getMessage());
} finally { } finally {
try{ try{
if(rs!=null) rs.close(); if(rs!=null) rs.close();
}catch(SQLException se2){ }catch(SQLException se2){
} }
// 关闭资源 // 关闭资源
try{ try{
if(pstemt!=null) pstemt.close(); if(pstemt!=null) pstemt.close();
}catch(SQLException se2){ }catch(SQLException se2){
}// 什么都不做 }// 什么都不做
try{ try{
if(con!=null) con.close(); if(con!=null) con.close();
}catch(SQLException se){ }catch(SQLException se){
se.printStackTrace(); se.printStackTrace();
} }
} }
} }
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.convert * @Package: com.gitee.mybatis.fl.convert
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.util; package com.gitee.flying.cattle.mdg.util;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import com.github.flying.cattle.mdg.entity.BasisInfo; import com.gitee.flying.cattle.mdg.entity.BasisInfo;
import com.github.flying.cattle.mdg.entity.ResultJson; import com.gitee.flying.cattle.mdg.entity.ResultJson;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 创建文件</P> * <p>说明: 创建文件</P>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
public class FreemarkerUtil { public class FreemarkerUtil {
public static ResultJson createFile(BasisInfo dataModel, String templateName, String filePath) { public static ResultJson createFile(BasisInfo dataModel, String templateName, String filePath) {
ResultJson result=new ResultJson(); ResultJson result=new ResultJson();
FileWriter out = null; FileWriter out = null;
String fileName=dataModel.getEntityName()+messageStr(templateName); String fileName=dataModel.getEntityName()+messageStr(templateName);
try { try {
// 通过FreeMarker的Confuguration读取相应的模板文件 // 通过FreeMarker的Confuguration读取相应的模板文件
Configuration configuration = new Configuration(Configuration.VERSION_2_3_28); Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
// 设置模板路径 // 设置模板路径
configuration.setClassForTemplateLoading(FreemarkerUtil.class, "/freemarker/ftl"); configuration.setClassForTemplateLoading(FreemarkerUtil.class, "/freemarker/ftl");
// 设置默认字体 // 设置默认字体
configuration.setDefaultEncoding("utf-8"); configuration.setDefaultEncoding("utf-8");
// 获取模板 // 获取模板
Template template = configuration.getTemplate(templateName); Template template = configuration.getTemplate(templateName);
File file = new File(filePath); File file = new File(filePath);
if (!file.getParentFile().exists()) { if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
} }
if(!file.exists()) { if(!file.exists()) {
file.createNewFile(); file.createNewFile();
}else { }else {
result.setCode(-1); result.setCode(-1);
result.setMessage("已经存在"+fileName); result.setMessage("已经存在"+fileName);
return result; return result;
} }
//设置输出流 //设置输出流
out = new FileWriter(file); out = new FileWriter(file);
//模板输出静态文件 //模板输出静态文件
template.process(dataModel, out); template.process(dataModel, out);
result.setCode(1); result.setCode(1);
result.setMessage("创建"+fileName+"成功"); result.setMessage("创建"+fileName+"成功");
return result; return result;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if(null != out) { if(null != out) {
try { try {
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
result.setCode(-1); result.setCode(-1);
result.setMessage("创建"+fileName+"失败"); result.setMessage("创建"+fileName+"失败");
return result; return result;
} }
public static String messageStr(String name) { public static String messageStr(String name) {
if (name.equals("entity.ftl")) { if (name.equals("entity.ftl")) {
name=".java"; name=".java";
} else if(name.equals("dao.ftl")){ } else if(name.equals("dao.ftl")){
name="Dao.java"; name="Dao.java";
} else if(name.equals("mapper.ftl")){ } else if(name.equals("mapper.ftl")){
name="Mapper.xml"; name="Mapper.xml";
} else if(name.equals("service.ftl")){ } else if(name.equals("service.ftl")){
name="Service.java"; name="Service.java";
} else if(name.equals("serviceImpl.ftl")){ } else if(name.equals("serviceImpl.ftl")){
name="ServiceImpl.java"; name="ServiceImpl.java";
} else if(name.equals("controller.ftl")){ } else if(name.equals("controller.ftl")){
name="Controller.java"; name="Controller.java";
} }
return name; return name;
} }
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.convert * @Package: com.gitee.mybatis.fl.convert
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.util; package com.gitee.flying.cattle.mdg.util;
import java.util.List; import java.util.List;
import com.github.flying.cattle.mdg.entity.BasisInfo; import com.gitee.flying.cattle.mdg.entity.BasisInfo;
import com.github.flying.cattle.mdg.entity.ResultJson; import com.gitee.flying.cattle.mdg.entity.ResultJson;
import com.github.flying.cattle.mdg.entity.PropertyInfo; import com.gitee.flying.cattle.mdg.entity.PropertyInfo;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 获取文件路径调用创建文件</P> * <p>说明: 获取文件路径调用创建文件</P>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
public class Generator { public class Generator {
//路径信息 //路径信息
public static final String ENTITY="entity"; public static final String ENTITY="entity";
public static final String DAO="dao"; public static final String DAO="dao";
public static final String DAO_IMPL="daoImpl"; public static final String DAO_IMPL="daoImpl";
public static final String SERVICE="service"; public static final String SERVICE="service";
public static final String SERVICE_IMPL="serviceImpl"; public static final String SERVICE_IMPL="serviceImpl";
public static final String CONTROLLER="controller"; public static final String CONTROLLER="controller";
public static final String SWAGGER_CONFIG="swaggerConfig"; public static final String SWAGGER_CONFIG="swaggerConfig";
//①创建实体类 //①创建实体类
public static ResultJson createEntity(String url,BasisInfo bi) { public static ResultJson createEntity(String url,BasisInfo bi) {
String fileUrl= getGeneratorFileUrl(url, bi.getEntityUrl(), bi.getEntityName(), ENTITY); String fileUrl= getGeneratorFileUrl(url, bi.getEntityUrl(), bi.getEntityName(), ENTITY);
return FreemarkerUtil.createFile(bi, "entity.ftl", fileUrl); return FreemarkerUtil.createFile(bi, "entity.ftl", fileUrl);
} }
//②创建DAO //②创建DAO
public static ResultJson createDao(String url,BasisInfo bi) { public static ResultJson createDao(String url,BasisInfo bi) {
String fileUrl= getGeneratorFileUrl(url, bi.getDaoUrl(), bi.getEntityName(), DAO); String fileUrl= getGeneratorFileUrl(url, bi.getDaoUrl(), bi.getEntityName(), DAO);
return FreemarkerUtil.createFile(bi, "dao.ftl", fileUrl); return FreemarkerUtil.createFile(bi, "dao.ftl", fileUrl);
} }
//③创建mapper配置文件 //③创建mapper配置文件
public static ResultJson createDaoImpl(String url,BasisInfo bi) { public static ResultJson createDaoImpl(String url,BasisInfo bi) {
String fileUrl= getGeneratorFileUrl(url, bi.getMapperUrl(), bi.getEntityName(), DAO_IMPL); String fileUrl= getGeneratorFileUrl(url, bi.getMapperUrl(), bi.getEntityName(), DAO_IMPL);
List<PropertyInfo> list=bi.getCis(); List<PropertyInfo> list=bi.getCis();
String agile=""; String agile="";
for (PropertyInfo propertyInfo : list) { for (PropertyInfo propertyInfo : list) {
agile=agile+propertyInfo.getColumn()+", "; agile=agile+propertyInfo.getColumn()+", ";
} }
agile=agile.substring(0, agile.length()-2); agile=agile.substring(0, agile.length()-2);
bi.setAgile(agile); bi.setAgile(agile);
return FreemarkerUtil.createFile(bi, "mapper.ftl", fileUrl); return FreemarkerUtil.createFile(bi, "mapper.ftl", fileUrl);
} }
//④创建SERVICE //④创建SERVICE
public static ResultJson createService(String url,BasisInfo bi) { public static ResultJson createService(String url,BasisInfo bi) {
String fileUrl= getGeneratorFileUrl(url, bi.getServiceUrl(), bi.getEntityName(), SERVICE); String fileUrl= getGeneratorFileUrl(url, bi.getServiceUrl(), bi.getEntityName(), SERVICE);
return FreemarkerUtil.createFile(bi, "service.ftl", fileUrl); return FreemarkerUtil.createFile(bi, "service.ftl", fileUrl);
} }
//⑤创建SERVICE_IMPL //⑤创建SERVICE_IMPL
public static ResultJson createServiceImpl(String url,BasisInfo bi) { public static ResultJson createServiceImpl(String url,BasisInfo bi) {
String fileUrl= getGeneratorFileUrl(url, bi.getServiceImplUrl(), bi.getEntityName(), SERVICE_IMPL); String fileUrl= getGeneratorFileUrl(url, bi.getServiceImplUrl(), bi.getEntityName(), SERVICE_IMPL);
return FreemarkerUtil.createFile(bi, "serviceImpl.ftl", fileUrl); return FreemarkerUtil.createFile(bi, "serviceImpl.ftl", fileUrl);
} }
//⑥创建CONTROLLER //⑥创建CONTROLLER
public static ResultJson createController(String url,BasisInfo bi) { public static ResultJson createController(String url,BasisInfo bi) {
createAbstractController( url, bi); //保证父类一直存在 createAbstractController( url, bi); //保证父类一直存在
String fileUrl= getGeneratorFileUrl(url, bi.getControllerUrl(), bi.getEntityName(), CONTROLLER); String fileUrl= getGeneratorFileUrl(url, bi.getControllerUrl(), bi.getEntityName(), CONTROLLER);
return FreemarkerUtil.createFile(bi, "controller.ftl", fileUrl); return FreemarkerUtil.createFile(bi, "controller.ftl", fileUrl);
} }
//⑦创建抽象的CONTROLLER //⑦创建抽象的CONTROLLER
public static ResultJson createAbstractController(String url,BasisInfo bi) { public static ResultJson createAbstractController(String url,BasisInfo bi) {
String fileUrl= getGeneratorFileUrl(url, bi.getAbstractControllerUrl(),"Abstract", CONTROLLER); String fileUrl= getGeneratorFileUrl(url, bi.getAbstractControllerUrl(),"Abstract", CONTROLLER);
return FreemarkerUtil.createFile(bi, "AbstractController.ftl", fileUrl); return FreemarkerUtil.createFile(bi, "AbstractController.ftl", fileUrl);
} }
//⑧创建CONTROLLER //⑧创建CONTROLLER
public static ResultJson createSwaggerConfig(String url,BasisInfo bi) { public static ResultJson createSwaggerConfig(String url,BasisInfo bi) {
String fileUrl= getGeneratorFileUrl(url,bi.getSwaggerConfigUrl(), "Swagger", SWAGGER_CONFIG); String fileUrl= getGeneratorFileUrl(url,bi.getSwaggerConfigUrl(), "Swagger", SWAGGER_CONFIG);
return FreemarkerUtil.createFile(bi, "SwaggerConfig.ftl", fileUrl); return FreemarkerUtil.createFile(bi, "SwaggerConfig.ftl", fileUrl);
} }
//生成文件路径和名字 //生成文件路径和名字
public static String getGeneratorFileUrl(String url,String packageUrl,String entityName, String type){ public static String getGeneratorFileUrl(String url,String packageUrl,String entityName, String type){
if (type.equals("entity")) { if (type.equals("entity")) {
return url+pageToUrl(packageUrl)+entityName+".java"; return url+pageToUrl(packageUrl)+entityName+".java";
}else if(type.equals("dao")) { }else if(type.equals("dao")) {
return url+pageToUrl(packageUrl)+entityName+"Dao.java"; return url+pageToUrl(packageUrl)+entityName+"Dao.java";
}else if(type.equals("daoImpl")) { }else if(type.equals("daoImpl")) {
return url+pageToUrl(packageUrl)+entityName+"Mapper.xml"; return url+pageToUrl(packageUrl)+entityName+"Mapper.xml";
}else if(type.equals("service")) { }else if(type.equals("service")) {
return url+pageToUrl(packageUrl)+entityName+"Service.java"; return url+pageToUrl(packageUrl)+entityName+"Service.java";
}else if(type.equals("serviceImpl")) { }else if(type.equals("serviceImpl")) {
return url+pageToUrl(packageUrl)+entityName+"ServiceImpl.java"; return url+pageToUrl(packageUrl)+entityName+"ServiceImpl.java";
}else if(type.equals("controller")) { }else if(type.equals("controller")) {
return url+pageToUrl(packageUrl)+entityName+"Controller.java"; return url+pageToUrl(packageUrl)+entityName+"Controller.java";
}else if(type.equals("swaggerConfig")){ }else if(type.equals("swaggerConfig")){
return url+pageToUrl(packageUrl)+entityName+"Config.java"; return url+pageToUrl(packageUrl)+entityName+"Config.java";
} }
return null; return null;
} }
public static String pageToUrl(String url) { public static String pageToUrl(String url) {
return url.replace(".", "/")+"/"; return url.replace(".", "/")+"/";
} }
} }
/** /**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved. * Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.util * @Package: com.gitee.mybatis.fl.util
* @author: flying-cattle * @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25 * @date: 2019年4月9日 下午8:15:25
*/ */
package com.github.flying.cattle.mdg.util; package com.gitee.flying.cattle.mdg.util;
import com.github.flying.cattle.mdg.convert.DateType; import com.gitee.flying.cattle.mdg.convert.DateType;
import com.github.flying.cattle.mdg.convert.MySqlTypeConvert; import com.gitee.flying.cattle.mdg.convert.MySqlTypeConvert;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
* <p>说明: 获奖java中需要的驼峰命名</P> * <p>说明: 获奖java中需要的驼峰命名</P>
* @version: v3.0.0 * @version: v3.0.0
* @author: flying-cattle * @author: flying-cattle
* *
* Modification History: * Modification History:
* Date Author Version Description * Date Author Version Description
*---------------------------------------------------------------* *---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v3.0.0 initialize * 2019年4月9日 flying-cattle v3.0.0 initialize
*/ */
public class MySqlToJavaUtil { public class MySqlToJavaUtil {
/** /**
* <p>说明:获取java类名</p> * <p>说明:获取java类名</p>
* @param table 表名 * @param table 表名
* @return String * @return String
*/ */
public static String getClassName(String table) { public static String getClassName(String table) {
table=changeToJavaFiled(table); table=changeToJavaFiled(table);
StringBuilder sbuilder = new StringBuilder(); StringBuilder sbuilder = new StringBuilder();
char[] cs = table.toCharArray(); char[] cs = table.toCharArray();
cs[0] -= 32; cs[0] -= 32;
sbuilder.append(String.valueOf(cs)); sbuilder.append(String.valueOf(cs));
return sbuilder.toString(); return sbuilder.toString();
} }
/** /**
* <p>说明:获取字段名,把"_"后面字母变大写</p> * <p>说明:获取字段名,把"_"后面字母变大写</p>
* @param field 字段名 * @param field 字段名
* @return String * @return String
*/ */
public static String changeToJavaFiled(String field) { public static String changeToJavaFiled(String field) {
String[] fields = field.split("_"); String[] fields = field.split("_");
StringBuilder sbuilder = new StringBuilder(fields[0]); StringBuilder sbuilder = new StringBuilder(fields[0]);
for (int i = 1; i < fields.length; i++) { for (int i = 1; i < fields.length; i++) {
char[] cs = fields[i].toCharArray(); char[] cs = fields[i].toCharArray();
cs[0] -= 32; cs[0] -= 32;
sbuilder.append(String.valueOf(cs)); sbuilder.append(String.valueOf(cs));
} }
return sbuilder.toString(); return sbuilder.toString();
} }
/** /**
* <p>说明:把sql的数据类型转为java需要的类型</p> * <p>说明:把sql的数据类型转为java需要的类型</p>
* @param sqlType sql类型 * @param sqlType sql类型
* @return String java类型 * @return String java类型
*/ */
public static String jdbcTypeToJavaType(String sqlType) { public static String jdbcTypeToJavaType(String sqlType) {
MySqlTypeConvert typeConvert= new MySqlTypeConvert(); MySqlTypeConvert typeConvert= new MySqlTypeConvert();
return typeConvert.processTypeConvert(DateType.ONLY_DATE, sqlType).getType(); return typeConvert.processTypeConvert(DateType.ONLY_DATE, sqlType).getType();
} }
/** /**
* <p>说明:把sql的数据类型转为java需要的类型</p> * <p>说明:把sql的数据类型转为java需要的类型</p>
* @param sqlType sql类型 * @param sqlType sql类型
* @return String java类型 * @return String java类型
*/ */
public static String jdbcTypeToJavaTypePck(String sqlType) { public static String jdbcTypeToJavaTypePck(String sqlType) {
MySqlTypeConvert typeConvert= new MySqlTypeConvert(); MySqlTypeConvert typeConvert= new MySqlTypeConvert();
return typeConvert.processTypeConvert(DateType.ONLY_DATE, sqlType).getPkg(); return typeConvert.processTypeConvert(DateType.ONLY_DATE, sqlType).getPkg();
} }
} }
...@@ -14,8 +14,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; ...@@ -14,8 +14,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.github.flying.cattle.mdg.aid.JsonResult; import com.gitee.flying.cattle.mdg.aid.JsonResult;
import com.github.flying.cattle.mdg.aid.PageParam; import com.gitee.flying.cattle.mdg.aid.PageParam;
<#if isSwagger=="true" > <#if isSwagger=="true" >
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
......
...@@ -9,10 +9,10 @@ package com.flying.cattle.mdg; ...@@ -9,10 +9,10 @@ package com.flying.cattle.mdg;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Date; import java.util.Date;
import com.github.flying.cattle.mdg.entity.BasisInfo; import com.gitee.flying.cattle.mdg.entity.BasisInfo;
import com.github.flying.cattle.mdg.util.EntityInfoUtil; import com.gitee.flying.cattle.mdg.util.EntityInfoUtil;
import com.github.flying.cattle.mdg.util.Generator; import com.gitee.flying.cattle.mdg.util.Generator;
import com.github.flying.cattle.mdg.util.MySqlToJavaUtil; import com.gitee.flying.cattle.mdg.util.MySqlToJavaUtil;
/** /**
* Copyright: Copyright (c) 2019 * Copyright: Copyright (c) 2019
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment