From 18d79cf314c72247bbd237214184e5077b993626 Mon Sep 17 00:00:00 2001 From: CHENTIANMING002 Date: Thu, 5 Aug 2021 11:04:01 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=94=AF=E6=8C=81common-mapper=202.=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dentity=E5=92=8Cplusentity=E7=9A=84swagger?= =?UTF-8?q?=E5=BC=95=E5=8C=85=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../system/generator/entity/ClassInfo.java | 1 + .../system/generator/util/TableParseUtil.java | 3 +- .../src/main/resources/template.json | 17 ++++++- .../code-generator/common-mapper/tkentity.ftl | 50 +++++++++++++++++++ .../code-generator/common-mapper/tkmapper.ftl | 16 ++++++ .../templates/code-generator/jpa/entity.ftl | 3 +- .../mybatis-plus/plusentity.ftl | 3 ++ 8 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 generator-web/src/main/resources/templates/code-generator/common-mapper/tkentity.ftl create mode 100644 generator-web/src/main/resources/templates/code-generator/common-mapper/tkmapper.ftl diff --git a/README.md b/README.md index be7f3ef..c09d2f0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ > #支持`MySQL`、Oracle、PgSQL三大主流数据库 > >generate to many popular templates by ddl-sql/insert-sql/simple json
-> 可通过`建表SQL语句`或`INSERT语句`或者`简单JSON`生成`JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL`相关模板代码. +> 可通过`建表SQL语句`或`INSERT语句`或者`简单JSON`生成`JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper`相关模板代码. > >thanks for your using and feedback,I'm inspired by the 600PV every day and github more than 700 stars
> 感谢大家的使用和反馈,每天六百的PV和获得超过七百多的星星是我前进和继续做下去的动力。 diff --git a/generator-web/src/main/java/com/softdev/system/generator/entity/ClassInfo.java b/generator-web/src/main/java/com/softdev/system/generator/entity/ClassInfo.java index cfecd96..5ccb9db 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/entity/ClassInfo.java +++ b/generator-web/src/main/java/com/softdev/system/generator/entity/ClassInfo.java @@ -13,6 +13,7 @@ import java.util.List; public class ClassInfo { private String tableName; + private String originTableName; private String className; private String classComment; private List fieldList; diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/TableParseUtil.java b/generator-web/src/main/java/com/softdev/system/generator/util/TableParseUtil.java index 97793e5..d08b828 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/util/TableParseUtil.java +++ b/generator-web/src/main/java/com/softdev/system/generator/util/TableParseUtil.java @@ -73,7 +73,7 @@ public class TableParseUtil { //优化对likeu.members这种命名的支持 tableName = tableName.substring(tableName.indexOf(".") + 1); } - + String originTableName = tableName; //ignore prefix if(tableName!=null && StringUtils.isNotNull(MapUtil.getString(paramInfo.getOptions(),"ignorePrefix"))){ tableName = tableName.replaceAll(MapUtil.getString(paramInfo.getOptions(),"ignorePrefix"),""); @@ -306,6 +306,7 @@ public class TableParseUtil { codeJavaInfo.setClassName(className); codeJavaInfo.setClassComment(classComment); codeJavaInfo.setFieldList(fieldList); + codeJavaInfo.setOriginTableName(originTableName); return codeJavaInfo; } diff --git a/generator-web/src/main/resources/template.json b/generator-web/src/main/resources/template.json index e95dad1..4357120 100644 --- a/generator-web/src/main/resources/template.json +++ b/generator-web/src/main/resources/template.json @@ -169,5 +169,20 @@ "description": "sql" } ] - } + }, + + { + "group": "common-mapper", + "templates": [{ + "id": "74", + "name": "tkentity", + "description": "tkentity" + }, + { + "id": "75", + "name": "tkmapper", + "description": "tkmapper" + } + ] +} ] \ No newline at end of file diff --git a/generator-web/src/main/resources/templates/code-generator/common-mapper/tkentity.ftl b/generator-web/src/main/resources/templates/code-generator/common-mapper/tkentity.ftl new file mode 100644 index 0000000..742dcb2 --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/common-mapper/tkentity.ftl @@ -0,0 +1,50 @@ +<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.entity; + +<#if isAutoImport?exists && isAutoImport==true> +<#if isLombok?exists && isLombok==true>import lombok.Data; +import java.util.Date; +import java.util.List; +import java.io.Serializable; +import javax.persistence.*; +<#if isSwagger?exists && isSwagger==true> +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd')} + */ +<#if isLombok?exists && isLombok==true>@Data +<#if isComment?exists && isComment==true>@Table(name="${classInfo.originTableName}")<#if isSwagger?exists && isSwagger==true> +@ApiModel("${classInfo.classComment}") +public class ${classInfo.className} implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> +<#list classInfo.fieldList as fieldItem > + <#if isComment?exists && isComment==true>/** + * ${fieldItem.fieldComment} + */<#if isSwagger?exists && isSwagger==true> + @ApiModelProperty("${fieldItem.fieldComment}") + <#if isComment?exists && isComment==true>@Column(name="${fieldItem.columnName}") + private ${fieldItem.fieldClass} ${fieldItem.fieldName}; + + + public ${classInfo.className}() { + } + + +<#if isLombok?exists && isLombok==false> + public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() { + return ${fieldItem.fieldName}; + } + + public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) { + this.${fieldItem.fieldName} = ${fieldItem.fieldName}; + } + +} diff --git a/generator-web/src/main/resources/templates/code-generator/common-mapper/tkmapper.ftl b/generator-web/src/main/resources/templates/code-generator/common-mapper/tkmapper.ftl new file mode 100644 index 0000000..3fdb960 --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/common-mapper/tkmapper.ftl @@ -0,0 +1,16 @@ +<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.mapper; +<#if isAutoImport?exists && isAutoImport==true> +import tk.mybatis.mapper.common.Mapper; +import org.apache.ibatis.annotations.Mapper; +import ${packageName}.entity.${classInfo.className}; + +/** + * @description ${classInfo.classComment}Mapper + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd')} + */ +@Mapper +public interface ${classInfo.className}Mapper extends Mapper<${classInfo.className}> { + + +} diff --git a/generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl b/generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl index bd30b4c..ceb1456 100644 --- a/generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl +++ b/generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl @@ -10,8 +10,9 @@ import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.GeneratedValue; +<#if isSwagger?exists && isSwagger==true> import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiModelProperty; /** * @description ${classInfo.classComment} diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl index 2cb9d33..52134ed 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl @@ -7,6 +7,9 @@ import java.util.List; import java.io.Serializable; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; +<#if isSwagger?exists && isSwagger==true> +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; /** * @description ${classInfo.classComment}