From 3bbca9d78099352ee8c80a4378b0cf5b9c6de842 Mon Sep 17 00:00:00 2001 From: "MOSHOW.K.ZHENG" Date: Sun, 28 Jun 2020 23:19:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Util=E4=B8=8B=E7=9A=84BeanUti?= =?UTF-8?q?l=EF=BC=8C=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9Amap.put=E7=9A=84?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E3=80=82=E6=95=B4=E5=90=88CRUD=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=88=B0SQL(CRUD)=E6=A8=A1=E6=9D=BF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 + .../src/main/resources/template.json | 30 ++-------- .../templates/code-generator/sql/delete.ftl | 9 --- .../templates/code-generator/sql/insert.ftl | 9 --- .../templates/code-generator/sql/select.ftl | 13 ----- .../templates/code-generator/sql/update.ftl | 11 ---- .../code-generator/util/beanutil.ftl | 41 +++++++++++++ .../templates/code-generator/util/json.ftl | 2 +- .../templates/code-generator/util/sql.ftl | 58 +++++++++++++++++++ .../templates/code-generator/util/util.ftl | 21 ------- .../templates/code-generator/util/xml.ftl | 2 +- .../src/main/resources/templates/index.ftl | 38 ++++-------- 12 files changed, 122 insertions(+), 115 deletions(-) delete mode 100644 generator-web/src/main/resources/templates/code-generator/sql/delete.ftl delete mode 100644 generator-web/src/main/resources/templates/code-generator/sql/insert.ftl delete mode 100644 generator-web/src/main/resources/templates/code-generator/sql/select.ftl delete mode 100644 generator-web/src/main/resources/templates/code-generator/sql/update.ftl create mode 100644 generator-web/src/main/resources/templates/code-generator/util/beanutil.ftl create mode 100644 generator-web/src/main/resources/templates/code-generator/util/sql.ftl delete mode 100644 generator-web/src/main/resources/templates/code-generator/util/util.ftl diff --git a/README.md b/README.md index ea18f72..3f3d33a 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ - 提供众多通用模板,易于使用,复制粘贴加简单修改即可完成CRUD操作 - 支持特殊字符模板(`#`请用`井`代替;`$`请用`¥`代替) - 根据comment=(mysql)或者comment on table(pgsql/oracle)生成类名注释 +- BeanUtil提供一些基本对象的使用方法供COPY + # Url @@ -33,6 +35,7 @@ |更新日期|更新内容| |----|----| +|20200628|优化Util下的BeanUtil,支持更多map.put的操作。整合CRUD模板到SQL(CRUD)模板。| |20200621|修复FreemarkerUtil的Path问题导致JAR包运行时无法获取template的问题。| |20200525|1.一些fix,关于封装工具类以及layui模板优化等.
2.优化表备注的获取逻辑.
3.生成时间格式改为yyyy-MM-dd,移除具体的时间,只保留日期| |20200522|1.新增insert-sql模式,支持对"insert into table (xxx) values (xxx)"语句进行处理,生成java代码(感谢三叔的建议).| diff --git a/generator-web/src/main/resources/template.json b/generator-web/src/main/resources/template.json index c318d15..ca98f76 100644 --- a/generator-web/src/main/resources/template.json +++ b/generator-web/src/main/resources/template.json @@ -139,9 +139,9 @@ }, { "id": "70", - "name": "util", + "name": "beanutil", "group": "util", - "description": "util" + "description": "beanutil" }, { "id": "71", @@ -156,27 +156,9 @@ "description": "xml" }, { - "id": "80", - "name": "select", - "group": "sql", - "description": "select" - }, - { - "id": "81", - "name": "insert", - "group": "sql", - "description": "insert" - }, - { - "id": "82", - "name": "update", - "group": "sql", - "description": "update" - }, - { - "id": "83", - "name": "delete", - "group": "sql", - "description": "delete" + "id": "73", + "name": "sql", + "group": "util", + "description": "sql" } ] \ No newline at end of file diff --git a/generator-web/src/main/resources/templates/code-generator/sql/delete.ftl b/generator-web/src/main/resources/templates/code-generator/sql/delete.ftl deleted file mode 100644 index 754c2b4..0000000 --- a/generator-web/src/main/resources/templates/code-generator/sql/delete.ftl +++ /dev/null @@ -1,9 +0,0 @@ -<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> -DELETE -FROM - ${classInfo.tableName} -WHERE -<#list classInfo.fieldList as fieldItem > - ${fieldItem.columnName} = ''<#if fieldItem_has_next>, -; - diff --git a/generator-web/src/main/resources/templates/code-generator/sql/insert.ftl b/generator-web/src/main/resources/templates/code-generator/sql/insert.ftl deleted file mode 100644 index 2e798ee..0000000 --- a/generator-web/src/main/resources/templates/code-generator/sql/insert.ftl +++ /dev/null @@ -1,9 +0,0 @@ -<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> -INSERT INTO ${classInfo.tableName} ( <#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>, ) -VALUES - ( - <#list classInfo.fieldList as fieldItem > - ''<#if fieldItem_has_next>, - - ); - diff --git a/generator-web/src/main/resources/templates/code-generator/sql/select.ftl b/generator-web/src/main/resources/templates/code-generator/sql/select.ftl deleted file mode 100644 index 2e1484d..0000000 --- a/generator-web/src/main/resources/templates/code-generator/sql/select.ftl +++ /dev/null @@ -1,13 +0,0 @@ -<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> -SELECT -<#list classInfo.fieldList as fieldItem > - ${fieldItem.columnName}<#if fieldItem_has_next>, - -FROM - ${classInfo.tableName} -WHERE -<#list classInfo.fieldList as fieldItem > - <#if fieldItem_index != 0>AND ${fieldItem.columnName} = '' -; - - diff --git a/generator-web/src/main/resources/templates/code-generator/sql/update.ftl b/generator-web/src/main/resources/templates/code-generator/sql/update.ftl deleted file mode 100644 index e441dc4..0000000 --- a/generator-web/src/main/resources/templates/code-generator/sql/update.ftl +++ /dev/null @@ -1,11 +0,0 @@ -<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> -UPDATE ${classInfo.tableName} -SET -<#list classInfo.fieldList as fieldItem > - ${fieldItem.columnName} = ''<#if fieldItem_has_next>, - -WHERE -<#list classInfo.fieldList as fieldItem > - ${fieldItem.columnName} = ''<#if fieldItem_has_next>, -; - diff --git a/generator-web/src/main/resources/templates/code-generator/util/beanutil.ftl b/generator-web/src/main/resources/templates/code-generator/util/beanutil.ftl new file mode 100644 index 0000000..b293944 --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/util/beanutil.ftl @@ -0,0 +1,41 @@ +/** +* ${classInfo.classComment}对象Get Set +* @author ${authorName} ${.now?string('yyyy-MM-dd')} +*/ + +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> +<#list classInfo.fieldList as fieldItem> +// ${fieldItem.fieldComment} +${fieldItem.fieldClass} ${fieldItem.fieldName} = ${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}(); + + +<#list classInfo.fieldList as fieldItem> +// ${fieldItem.fieldComment} +${classInfo.className?uncap_first}.set${fieldItem.fieldName?cap_first}(); + + +<#list classInfo.fieldList as fieldItem> +// ${fieldItem.fieldComment} +${classInfo.className?uncap_first}.set${fieldItem.fieldName?cap_first}(${classInfo.className?uncap_first}2.get${fieldItem.fieldName?cap_first}()); + + +<#list classInfo.fieldList as fieldItem> +// ${fieldItem.fieldComment} +map.put("${fieldItem.fieldName?cap_first}",${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}()); + + +<#list classInfo.fieldList as fieldItem> +// ${fieldItem.fieldComment} +map.put("${fieldItem.columnName}",${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}()); + + +<#list classInfo.fieldList as fieldItem> +map.put("${fieldItem.fieldComment}",${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}()); + + +<#list classInfo.fieldList as fieldItem> +// ${fieldItem.fieldComment} +map.put("${fieldItem.fieldName?cap_first}",${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}()); + + + diff --git a/generator-web/src/main/resources/templates/code-generator/util/json.ftl b/generator-web/src/main/resources/templates/code-generator/util/json.ftl index a0be13a..8de14f6 100644 --- a/generator-web/src/main/resources/templates/code-generator/util/json.ftl +++ b/generator-web/src/main/resources/templates/code-generator/util/json.ftl @@ -1,7 +1,7 @@ <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> { <#list classInfo.fieldList as fieldItem> - "${fieldItem.fieldName}":""<#if fieldItem_has_next>, + "${fieldItem.fieldName}":"${fieldItem.fieldComment}"<#if fieldItem_has_next>, } diff --git a/generator-web/src/main/resources/templates/code-generator/util/sql.ftl b/generator-web/src/main/resources/templates/code-generator/util/sql.ftl new file mode 100644 index 0000000..848f6e8 --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/util/sql.ftl @@ -0,0 +1,58 @@ + +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> + SELECT + <#list classInfo.fieldList as fieldItem > + ${fieldItem.columnName}<#if fieldItem_has_next>, + + FROM + ${classInfo.tableName} + WHERE + <#list classInfo.fieldList as fieldItem > + <#if fieldItem_index != 0>AND ${fieldItem.columnName} = '' + ; + + +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> + SELECT + * + FROM + ${classInfo.tableName} t1 + LEFT JOIN xxx t2 + ON t1.${classInfo.tableName}_id=t2.${classInfo.tableName}_id + WHERE 1=1; + + +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> + INSERT INTO ${classInfo.tableName} ( <#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>, ) + VALUES + ( + <#list classInfo.fieldList as fieldItem > + ''<#if fieldItem_has_next>, + + ); + + + +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> + UPDATE ${classInfo.tableName} + SET + <#list classInfo.fieldList as fieldItem > + ${fieldItem.columnName} = ''<#if fieldItem_has_next>, + + WHERE + <#list classInfo.fieldList as fieldItem > + ${fieldItem.columnName} = ''<#if fieldItem_has_next>, + ; + + + + +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> + DELETE + FROM + ${classInfo.tableName} + WHERE + <#list classInfo.fieldList as fieldItem > + ${fieldItem.columnName} = ''<#if fieldItem_has_next>, + ; + diff --git a/generator-web/src/main/resources/templates/code-generator/util/util.ftl b/generator-web/src/main/resources/templates/code-generator/util/util.ftl deleted file mode 100644 index 13da0ab..0000000 --- a/generator-web/src/main/resources/templates/code-generator/util/util.ftl +++ /dev/null @@ -1,21 +0,0 @@ -/** -* ${classInfo.classComment}对象Get Set -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ - -<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> -<#list classInfo.fieldList as fieldItem> -// ${fieldItem.fieldComment} -${fieldItem.fieldClass} ${fieldItem.fieldName} = ${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}(); - - -<#list classInfo.fieldList as fieldItem> -// ${fieldItem.fieldComment} -${classInfo.className?uncap_first}.set${fieldItem.fieldName?cap_first}(); - - -<#list classInfo.fieldList as fieldItem> -// ${fieldItem.fieldComment} -${classInfo.className?uncap_first}.set${fieldItem.fieldName?cap_first}(${classInfo.className?uncap_first}2.get${fieldItem.fieldName?cap_first}();); - - diff --git a/generator-web/src/main/resources/templates/code-generator/util/xml.ftl b/generator-web/src/main/resources/templates/code-generator/util/xml.ftl index d815657..3959cfc 100644 --- a/generator-web/src/main/resources/templates/code-generator/util/xml.ftl +++ b/generator-web/src/main/resources/templates/code-generator/util/xml.ftl @@ -5,7 +5,7 @@ <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> <${classInfo.className}> <#list classInfo.fieldList as fieldItem> - <${fieldItem.fieldName}> + <${fieldItem.fieldName}>${fieldItem.fieldComment} diff --git a/generator-web/src/main/resources/templates/index.ftl b/generator-web/src/main/resources/templates/index.ftl index 35d5727..c50975f 100644 --- a/generator-web/src/main/resources/templates/index.ftl +++ b/generator-web/src/main/resources/templates/index.ftl @@ -306,16 +306,14 @@ CREATE TABLE 'userinfo' ( @@ -390,28 +388,16 @@ CREATE TABLE 'userinfo' ( - -
-