From b30ce868ff8b0409fdbcad4149488c4fae0fd289 Mon Sep 17 00:00:00 2001 From: moshowgame Date: Mon, 18 May 2020 00:18:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Emapper2(Mybatis-Annotation?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF)(=E6=84=9F=E8=B0=A2@baisi525=E5=92=8C@CHKEGi?= =?UTF-8?q?t=E7=9A=84=E5=BB=BA=E8=AE=AE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 +++- .../system/generator/util/FreemarkerUtil.java | 4 +- .../src/main/resources/template.json | 6 ++ .../mybatis-plus/plusentity.ftl | 4 +- .../code-generator/mybatis/mapper2.ftl | 56 +++++++++++++++++++ .../src/main/resources/templates/index.ftl | 11 ++-- 6 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 generator-web/src/main/resources/templates/code-generator/mybatis/mapper2.ftl diff --git a/README.md b/README.md index 9137cf8..d286c6d 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,16 @@ # Description - √ 基于SpringBoot2+Freemarker+Bootstrap -- √ 以释放双手为目的 +- √ 以解放双手为目的,减少大量重复的CRUD工作 - √ 支持mysql/oracle/pgsql三大数据库 - √ 用DDL-SQL语句生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL相关代码. +# Advantage +- 自动记忆最近生成的内容,最多保留9个 +- 支持特殊字符模板(`#`请用`井`代替;`$`请用`¥`代替) +- 提供众多通用模板,易于使用,复制粘贴加简单修改即可完成CRUD操作 +- 支持JSON逆向生成(只支持简单的一级树) + # Url @@ -20,14 +26,14 @@ |CSDN博客|http://zhengkai.blog.csdn.net| |最新Jar包|https://github.com/moshowgame/SpringBootCodeGenerator/releases| -感谢bejson三叔将他部署在[BEJSON](www.bejson.com)上,目前是besjon专供工具(线上版本不一定是最新的,会有延迟,请谅解,谢谢). +感谢bejson三叔将他部署在[BEJSON](www.bejson.com)上,目前是besjon专供的金牌工具(线上版本不一定是最新的,会有延迟,请谅解,谢谢). # Update |更新日期|更新内容| |-|-| -|20200517|1.代码重构!异常处理优化,Freemarker相关工具类优化,简化模板生成部分,通过template.json来配置需要生成的模板,不需要配置java文件。 2.修复包含comment关键字时注释无法识别的问题。(感谢@1nchaos的反馈) 3.赞赏优化,感谢大家的赞赏| +|20200517|1.代码重构!异常处理优化,Freemarker相关工具类优化,简化模板生成部分,通过template.json来配置需要生成的模板,不需要配置java文件。 2.修复包含comment关键字时注释无法识别的问题。(感谢@1nchaos的反馈) 3.赞赏优化,感谢大家的赞赏 4.新增mapper2(Mybatis-Annotation模板)(感谢@baisi525和@CHKEGit的建议)。| |20200503|1.优化对特殊字符的处理,对于包含#和$等特殊字符的,在模板使用井和¥代替便可,escapeString方法会自动处理
2.优化mybatisplus实体类相关(感谢@chunchengmeigui的反馈) 3.修优化对所有类型的判断(感谢@cnlw的反馈) 4.移除swagger-entity,该功能已经包含在‘swagger-ui’的下拉选项中 5.升级hutool和lombok版本| |20200306|1.提交一套layuimini+mybatisplus的模板. 2.修复mybatisplus一些相关问题. | |20200206|1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@Column带name参数(感谢@liuyu-struggle的建议) 3.去除mybatis模板中的方括号[]和修改模板里的类注释样式(感谢@gaohanghang的PR)| diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java b/generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java index 33a56e7..07db20b 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java +++ b/generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java @@ -31,7 +31,7 @@ public class FreemarkerUtil { * 传入需要转义的字符串进行转义 * 20200503 zhengkai.blog.csdn.net * */ - public String escapeString(String originStr){ + public static String escapeString(String originStr){ return originStr.replaceAll("井","\\#").replaceAll("¥","\\$"); } @@ -88,7 +88,7 @@ public class FreemarkerUtil { throws IOException, TemplateException { Template template = freemarkerConfig.getTemplate(templateName); - String htmlText = processTemplateIntoString(template, params); + String htmlText = escapeString(processTemplateIntoString(template, params)); return htmlText; } diff --git a/generator-web/src/main/resources/template.json b/generator-web/src/main/resources/template.json index 24741b9..c318d15 100644 --- a/generator-web/src/main/resources/template.json +++ b/generator-web/src/main/resources/template.json @@ -65,6 +65,12 @@ "group": "mybatis", "description": "model" }, + { + "id": "26", + "name": "mapper2", + "group": "mybatis", + "description": "mapper annotation" + }, { "id": "30", "name": "entity", 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 887dd2a..dce63e0 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 @@ -12,8 +12,8 @@ import com.baomidou.mybatisplus.annotation.TableId; * @author ${authorName} * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} */ -@Data -<#if swagger?exists && swagger==true>@ApiModel("${classInfo.classComment}") +@Data<#if swagger?exists && swagger==true> +@ApiModel("${classInfo.classComment}") public class ${classInfo.className} implements Serializable { private static final long serialVersionUID = 1L; diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/mapper2.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/mapper2.ftl new file mode 100644 index 0000000..07233e4 --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/mapper2.ftl @@ -0,0 +1,56 @@ +package ${packageName}.mapper; + +import org.apache.ibatis.annotations.*; +import org.springframework.stereotype.Repository; +import java.util.List; + +/** + * @description ${classInfo.classComment}Mapper + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ +@Mapper +@Repository +public interface ${classInfo.className}Mapper { + + @Select("select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{id}") + public ${classInfo.className} getById(Integer id); + + @Options(useGeneratedKeys=true,keyProperty="${classInfo.className?uncap_first}Id") + @Insert("insert into ${classInfo.tableName}" + "(<#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>,)" + "values(<#list classInfo.fieldList as fieldItem >${fieldItem.fieldName}<#if fieldItem_has_next>,)") + public Integer insert(${classInfo.className} ${classInfo.className?uncap_first}); + + @Delete(value = "delete from ${classInfo.tableName} where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id}") + boolean delete(Integer id); + + @Update(value = "update ${classInfo.tableName} set " + <#list classInfo.fieldList as fieldItem > + <#if fieldItem.columnName != "id">+" ${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next>," + + +" where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id} ") + boolean update(${classInfo.className} ${classInfo.className?uncap_first}); + + + @Results(value = { + <#list classInfo.fieldList as fieldItem > + @Result(property = "${fieldItem.fieldName}", column = "${fieldItem.columnName}")<#if fieldItem_has_next>, + + }) + @Select(value = "select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{queryParam}") + ${classInfo.className} selectOne(String queryParam); + + @Results(value = { + <#list classInfo.fieldList as fieldItem > + @Result(property = "${fieldItem.fieldName}", column = "${fieldItem.columnName}")<#if fieldItem_has_next>, + + }) + @Select(value = "select * from ${classInfo.tableName} where " + <#list classInfo.fieldList as fieldItem > + +" ${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next> or " + + ) + List<${classInfo.className}> selectList(${classInfo.className} ${classInfo.className?uncap_first}); + +} \ No newline at end of file diff --git a/generator-web/src/main/resources/templates/index.ftl b/generator-web/src/main/resources/templates/index.ftl index c806b6d..abe24aa 100644 --- a/generator-web/src/main/resources/templates/index.ftl +++ b/generator-web/src/main/resources/templates/index.ftl @@ -217,7 +217,9 @@

Spring Boot Code Generator!

- √基于SpringBoot2+Freemarker的代码生成器,√以释放双手为目的,√支持mysql/oracle/pgsql三大数据库,
+ √基于SpringBoot2+Freemarker的代码生成器
+ √以解放双手为目的,减少大量重复的CRUD工作
+ √支持mysql/oracle/pgsql三大数据库
√用DDL-SQL语句生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL相关代码。
如果发现有SQL语句不能识别,请留言,同时欢迎大家提PR赞赏,谢谢!查看版本

@@ -279,7 +281,7 @@