Commit 40b90936 by bianpeng

修改目录结构

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