From 90750d420f560bce03be00c3d8e29b0a28fe9b5c Mon Sep 17 00:00:00 2001 From: gaohanghang <1341947277@qq.com> Date: Tue, 14 Jan 2020 22:54:18 +0800 Subject: [PATCH 001/116] =?UTF-8?q?1.=20=E5=8E=BB=E9=99=A4=20mybatis=20?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E4=B8=AD=E7=9A=84=E6=96=B9=E6=8B=AC=E5=8F=B7?= =?UTF-8?q?[]=EF=BC=8C=E4=BD=BF=E4=BB=A3=E7=A0=81=E6=9B=B4=E7=BE=8E?= =?UTF-8?q?=E8=A7=82=202.=20=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF=E9=87=8C?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E6=B3=A8=E9=87=8A=E6=A0=B7=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E6=B3=A8=E9=87=8A=E6=9B=B4=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beetlsql/beetlcontroller.ftl | 7 ++++--- .../code-generator/beetlsql/beetlentity.ftl | 7 ++++--- .../beetlsql/beetlentitydto.ftl | 7 ++++--- .../code-generator/jdbc-template/jtdao.ftl | 7 ++++--- .../jdbc-template/jtdaoimpl.ftl | 7 ++++--- .../templates/code-generator/jpa/entity.ftl | 7 ++++--- .../code-generator/jpa/jpacontroller.ftl | 7 ++++--- .../code-generator/jpa/repository.ftl | 7 ++++--- .../mybatis-plus/pluscontroller.ftl | 7 ++++--- .../mybatis-plus/plusmapper.ftl | 7 ++++--- .../code-generator/mybatis/controller.ftl | 18 ++++++++--------- .../code-generator/mybatis/mapper.ftl | 20 +++++++++---------- .../code-generator/mybatis/model.ftl | 7 ++++--- .../code-generator/mybatis/service.ftl | 8 ++++---- .../code-generator/mybatis/service_impl.ftl | 8 ++++---- 15 files changed, 71 insertions(+), 60 deletions(-) diff --git a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl b/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl index f8b67360..a9604ed7 100644 --- a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl @@ -7,9 +7,10 @@ import java.util.List; import java.util.Map; /** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @RestController @RequestMapping("/${classInfo.className?uncap_first}") public class ${classInfo.className}Controller { diff --git a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl b/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl index a3c42aea..381f3ae1 100644 --- a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl +++ b/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl @@ -4,9 +4,10 @@ import java.util.Date; import java.util.List; /** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @Data public class ${classInfo.className} implements Serializable { diff --git a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentitydto.ftl b/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentitydto.ftl index 9e25e2f4..9665c5c1 100644 --- a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentitydto.ftl +++ b/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentitydto.ftl @@ -6,8 +6,9 @@ import java.util.Date; import java.util.List; /** - * ${classInfo.classComment} - * @author ${authorName} ${.now?string('yyyy-MM-dd')} + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} */ @Data @ApiModel("${classInfo.classComment}") @@ -23,4 +24,4 @@ public class ${classInfo.className}DTO { } -} \ No newline at end of file +} diff --git a/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl b/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl index 4e2a8f9c..14bc2451 100644 --- a/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl +++ b/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl @@ -2,9 +2,10 @@ import java.util.List; /** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ public interface I${classInfo.className}DAO { int add(${classInfo.className} ${classInfo.className?uncap_first}); diff --git a/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl b/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl index 5e138826..a3b62c02 100644 --- a/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl +++ b/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl @@ -6,9 +6,10 @@ import org.springframework.stereotype.Repository; import java.util.List; /** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @Repository public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao{ 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 d2cb299c..6bb8cbff 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 @@ -13,9 +13,10 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; /** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @Entity @Data @Table(name="${classInfo.tableName}") diff --git a/generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl b/generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl index 59975cee..bbe7ff26 100644 --- a/generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl @@ -15,9 +15,10 @@ import java.util.List; import java.util.Map; /** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @RestController @RequestMapping("/${classInfo.className?uncap_first}") public class ${classInfo.className}Controller { diff --git a/generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl b/generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl index e11838ab..dbfb4695 100644 --- a/generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl +++ b/generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl @@ -14,9 +14,10 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; /** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @Repository public interface ${classInfo.className}Repository extends JpaRepository<${classInfo.className},Integer> { diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl index f6c517f4..3686847c 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl @@ -11,9 +11,10 @@ import java.util.List; import java.util.Map; /** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @RestController @RequestMapping("/${classInfo.className?uncap_first}") public class ${classInfo.className}Controller { diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl index 37e9456f..231dbd5b 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl @@ -3,9 +3,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.springframework.stereotype.Repository; /** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @Repository public interface ${classInfo.className}Mapper extends BaseMapper<${classInfo.className}> { diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl index 7af61a33..37cd417b 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl @@ -9,10 +9,10 @@ import java.util.List; import java.util.Map; /** -* ${classInfo.classComment} -* @author ${authorName} -* @date ${.now?string('yyyy/MM/dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @RestController @RequestMapping(value = "/${classInfo.className}") public class ${classInfo.className}Controller { @@ -21,7 +21,7 @@ public class ${classInfo.className}Controller { private ${classInfo.className}Service ${classInfo.className?uncap_first}Service; /** - * [新增] + * 新增 * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ @@ -31,7 +31,7 @@ public class ${classInfo.className}Controller { } /** - * [刪除] + * 刪除 * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ @@ -41,7 +41,7 @@ public class ${classInfo.className}Controller { } /** - * [更新] + * 更新 * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ @@ -51,7 +51,7 @@ public class ${classInfo.className}Controller { } /** - * [查询] 根据主键 id 查询 + * 查询 根据主键 id 查询 * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ @@ -61,7 +61,7 @@ public class ${classInfo.className}Controller { } /** - * [查询] 分页查询 + * 查询 分页查询 * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl index 2512852e..f6d024d7 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl @@ -4,51 +4,51 @@ import org.springframework.stereotype.Repository; import java.util.List; /** -* ${classInfo.classComment} -* @author ${authorName} -* @date ${.now?string('yyyy/MM/dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @Mapper @Repository public interface ${classInfo.className}Mapper { /** - * [新增] + * 新增 * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ int insert(${classInfo.className} ${classInfo.className?uncap_first}); /** - * [刪除] + * 刪除 * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ int delete(int id); /** - * [更新] + * 更新 * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ int update(${classInfo.className} ${classInfo.className?uncap_first}); /** - * [查询] 根据主键 id 查询 + * 查询 根据主键 id 查询 * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ ${classInfo.className} load(int id); /** - * [查询] 分页查询 + * 查询 分页查询 * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ List<${classInfo.className}> pageList(int offset,int pagesize); /** - * [查询] 分页查询 count + * 查询 分页查询 count * @author ${authorName} * @date ${.now?string('yyyy/MM/dd')} **/ diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/model.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/model.ftl index e7909be8..b360fdd8 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/model.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/model.ftl @@ -3,9 +3,10 @@ import java.util.Date; import java.util.List; /** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ public class ${classInfo.className} implements Serializable { private static final long serialVersionUID = 1L; diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl index 0e78ee73..7dfcf72d 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl @@ -1,10 +1,10 @@ import java.util.Map; /** -* ${classInfo.classComment} -* @author ${authorName} -* @date ${.now?string('yyyy/MM/dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ public interface ${classInfo.className}Service { /** diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl index a5d6e89d..86b30e86 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl @@ -7,10 +7,10 @@ import java.util.List; import java.util.Map; /** -* ${classInfo.classComment} -* @author ${authorName} -* @date ${.now?string('yyyy/MM/dd')} -*/ + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} + */ @Service public class ${classInfo.className}ServiceImpl implements ${classInfo.className}Service { From 2316fb1780da5e46a00f6171b6bc7e1181879ba4 Mon Sep 17 00:00:00 2001 From: "MOSHOW.K.ZHENG" Date: Wed, 5 Feb 2020 21:44:07 +0800 Subject: [PATCH 002/116] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD=EF=BC=8C=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=9C=80=E8=BF=91=E7=94=9F=E6=88=90=E7=9A=84?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=202.=E6=96=B0=E5=A2=9Eswagger=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E9=80=89=E9=A1=B9=E5=92=8C=E4=BF=AE=E5=A4=8D@Column?= =?UTF-8?q?=E5=B8=A6name=E5=8F=82=E6=95=B0(=E6=84=9F=E8=B0=A2@liuyu-strugg?= =?UTF-8?q?le=E7=9A=84=E5=BB=BA=E8=AE=AE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@Column带name参数(感谢@liuyu-struggle的建议) --- README.md | 1 + .../generator/controller/IndexController.java | 6 ++ .../system/generator/entity/ParamInfo.java | 1 + .../service/GeneratorServiceImpl.java | 2 +- .../src/main/resources/static/version.json | 2 +- .../templates/code-generator/jpa/entity.ftl | 10 +-- .../src/main/resources/templates/index.ftl | 63 ++++++++++++++++++- 7 files changed, 75 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 79ee06d9..6a5b2bd3 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ |更新日期|更新内容| |-|-| +|20200206|1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@Column带name参数(感谢@liuyu-struggle的建议)| |20191229|1.修复bejson安全防护策略拦截问题(感谢@liangbintao和@1808083642的反馈) 2.优化字段名含date字符串的处理(感谢@smilexzh的反馈) 3.控制台动态输出项目访问地址(感谢@gaohanghang的提交)| |20191128|1.修复支持string-copy导致的以n结尾的字母不显示问题 2.jpa-entity新增swagger@ApiModel@ApiModelProperty注解和SQL字段@Column注解(感谢@yjq907的建议) | |20191126|1.springboot2内置tomcat更换为性能更强大的undertow 2.修复tinyintTransType参数丢失问题 | diff --git a/generator-web/src/main/java/com/softdev/system/generator/controller/IndexController.java b/generator-web/src/main/java/com/softdev/system/generator/controller/IndexController.java index 7e08e9f4..528cb5bc 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/controller/IndexController.java +++ b/generator-web/src/main/java/com/softdev/system/generator/controller/IndexController.java @@ -1,5 +1,6 @@ package com.softdev.system.generator.controller; +import com.alibaba.fastjson.JSON; import com.softdev.system.generator.entity.ClassInfo; import com.softdev.system.generator.entity.ParamInfo; import com.softdev.system.generator.entity.ReturnT; @@ -60,9 +61,14 @@ public ReturnT> codeGenerate(@RequestBody ParamInfo paramInf // process the param Map params = new HashMap(8); params.put("classInfo", classInfo); + params.put("tableName", classInfo==null?System.currentTimeMillis():classInfo.getTableName()); params.put("authorName", paramInfo.getAuthorName()); params.put("packageName", paramInfo.getPackageName()); params.put("returnUtil", paramInfo.getReturnUtil()); + params.put("swagger", paramInfo.isSwagger()); + + //log the params + //log.info(JSON.toJSONString(paramInfo)); log.info("generator table:"+(classInfo==null?"":classInfo.getTableName()) +",field size:"+((classInfo==null||classInfo.getFieldList()==null)?"":classInfo.getFieldList().size())); diff --git a/generator-web/src/main/java/com/softdev/system/generator/entity/ParamInfo.java b/generator-web/src/main/java/com/softdev/system/generator/entity/ParamInfo.java index 7ca56fb0..cdf616af 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/entity/ParamInfo.java +++ b/generator-web/src/main/java/com/softdev/system/generator/entity/ParamInfo.java @@ -15,6 +15,7 @@ public class ParamInfo { private String nameCaseType; private String tinyintTransType; private String dataType; + private boolean swagger; @Data public static class NAME_CASE_TYPE{ diff --git a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java b/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java index ce857ea2..6e601958 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java +++ b/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java @@ -25,7 +25,7 @@ public class GeneratorServiceImpl implements GeneratorService { public Map getResultByParams(Map params) throws IOException, TemplateException { // result Map result = new HashMap(32); - + result.put("tableName",params.get("tableName")+""); //UI result.put("swagger-ui", freemarkerTool.processString("code-generator/ui/swagger-ui.ftl", params)); result.put("element-ui", freemarkerTool.processString("code-generator/ui/element-ui.ftl", params)); diff --git a/generator-web/src/main/resources/static/version.json b/generator-web/src/main/resources/static/version.json index b044f172..4d7211c0 100644 --- a/generator-web/src/main/resources/static/version.json +++ b/generator-web/src/main/resources/static/version.json @@ -1 +1 @@ -{"version": "20191229"} \ No newline at end of file +{"version": "20200206"} \ No newline at end of file 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 d2cb299c..85681503 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 @@ -18,8 +18,8 @@ import io.swagger.annotations.ApiModelProperty; */ @Entity @Data -@Table(name="${classInfo.tableName}") -@ApiModel("${classInfo.classComment}") +@Table(name="${classInfo.tableName}")<#if swagger?exists && swagger==true> +@ApiModel("${classInfo.classComment}") public class ${classInfo.className} implements Serializable { private static final long serialVersionUID = 1L; @@ -30,9 +30,9 @@ public class ${classInfo.className} implements Serializable { <#list classInfo.fieldList as fieldItem > /** * ${fieldItem.fieldComment} - */ - @ApiModelProperty("${fieldItem.fieldComment}") - @Column("${fieldItem.columnName}") + */<#if swagger?exists && swagger==true> + @ApiModelProperty("${fieldItem.fieldComment}") + @Column(name="${fieldItem.columnName}") private ${fieldItem.fieldClass} ${fieldItem.fieldName}; diff --git a/generator-web/src/main/resources/templates/index.ftl b/generator-web/src/main/resources/templates/index.ftl index b27c7fcf..eb151fe2 100644 --- a/generator-web/src/main/resources/templates/index.ftl +++ b/generator-web/src/main/resources/templates/index.ftl @@ -59,6 +59,12 @@ }); return o; }; + var historyCount=0; + //初始化清除session + if (window.sessionStorage){ + //修复当F5刷新的时候,session没有清空各个值,但是页面的button没了。 + sessionStorage.clear(); + } /** * 生成代码 */ @@ -70,7 +76,8 @@ "authorName":$("#authorName").val(), "dataType":$("#dataType").val(), "tinyintTransType":$("#tinyintTransType").val(), - "nameCaseType":$("#nameCaseType").val() + "nameCaseType":$("#nameCaseType").val(), + "swagger":$("#isSwagger").val() }; $.ajax({ type: 'POST', @@ -81,9 +88,11 @@ success: function (data) { if (data.code === 200) { codeData = data.data; - genCodeArea.setValue(codeData.beetlentity); + genCodeArea.setValue(codeData.entity); genCodeArea.setSize('auto', 'auto'); $.toast("√ 代码生成成功"); + //添加历史记录 + addHistory(codeData); } else { $.toast("× 代码生成失败 :"+data.msg); } @@ -91,6 +100,45 @@ }); return false; }); + /** + * 切换历史记录 + */ + function getHistory(tableName){ + if (window.sessionStorage){ + var valueSession = sessionStorage.getItem(tableName); + codeData = JSON.parse(valueSession); + $.toast("$ 切换历史记录成功:"+tableName); + genCodeArea.setValue(codeData.entity); + }else{ + console.log("浏览器不支持sessionStorage"); + } + } + /** + * 添加历史记录 + */ + function addHistory(data){ + if (window.sessionStorage){ + //console.log(historyCount); + if(historyCount>=9){ + $("#history").find(".btn:last").remove(); + historyCount--; + } + var tableName=data.tableName; + var valueSession = sessionStorage.getItem(tableName); + if(valueSession!==undefined && valueSession!=null){ + sessionStorage.removeItem(tableName); + }else{ + $("#history").prepend(''); + //$("#history").prepend(''); + $("#his-"+tableName).bind('click', function () {getHistory(tableName)}); + } + sessionStorage.setItem(tableName,JSON.stringify(data)); + historyCount++; + }else{ + console.log("浏览器不支持sessionStorage"); + } + } + /** * 按钮事件组 */ @@ -169,7 +217,7 @@

Spring Boot Code Generator!

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

@@ -219,6 +267,14 @@ <#----> +
+ swagger-ui +
+

+

From e78f38e3c9b7ee0dbe6f6654693b1cba832b1e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moshow=E9=83=91=E9=94=B4?= Date: Wed, 5 Feb 2020 21:52:23 +0800 Subject: [PATCH 003/116] =?UTF-8?q?=E5=8E=BB=E9=99=A4mybatis=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E4=B8=AD=E7=9A=84=E6=96=B9=E6=8B=AC=E5=8F=B7[]?= =?UTF-8?q?=E5=92=8C=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF=E9=87=8C=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E6=B3=A8=E9=87=8A=E6=A0=B7=E5=BC=8F(=E6=84=9F?= =?UTF-8?q?=E8=B0=A2@gaohanghang=E7=9A=84PR)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去除mybatis模板中的方括号[]和修改模板里的类注释样式(感谢@gaohanghang的PR) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a5b2bd3..18162f6e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ |更新日期|更新内容| |-|-| -|20200206|1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@Column带name参数(感谢@liuyu-struggle的建议)| +|20200206|1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@Column带name参数(感谢@liuyu-struggle的建议) 3.去除mybatis模板中的方括号[]和修改模板里的类注释样式(感谢@gaohanghang的PR)| |20191229|1.修复bejson安全防护策略拦截问题(感谢@liangbintao和@1808083642的反馈) 2.优化字段名含date字符串的处理(感谢@smilexzh的反馈) 3.控制台动态输出项目访问地址(感谢@gaohanghang的提交)| |20191128|1.修复支持string-copy导致的以n结尾的字母不显示问题 2.jpa-entity新增swagger@ApiModel@ApiModelProperty注解和SQL字段@Column注解(感谢@yjq907的建议) | |20191126|1.springboot2内置tomcat更换为性能更强大的undertow 2.修复tinyintTransType参数丢失问题 | From 45484d8949480cac94c1494b266e01adb2a830e3 Mon Sep 17 00:00:00 2001 From: "MOSHOW.K.ZHENG" Date: Fri, 6 Mar 2020 23:16:09 +0800 Subject: [PATCH 004/116] =?UTF-8?q?20200306=E6=8F=90=E4=BA=A4=E4=B8=80?= =?UTF-8?q?=E5=A5=97layuimini+mybatisplus=E7=9A=84=E6=A8=A1=E6=9D=BF.?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmybatisplus=E4=B8=80=E4=BA=9B=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../system/generator/config/ServerConfig.java | 10 +- .../service/GeneratorServiceImpl.java | 2 + .../src/main/resources/static/version.json | 2 +- .../mybatis-plus/pluscontroller.ftl | 77 ++++--- .../mybatis-plus/plusmapper.ftl | 6 +- .../code-generator/ui/layui-edit.ftl | 78 +++++++ .../code-generator/ui/layui-list.ftl | 195 ++++++++++++++++++ .../src/main/resources/templates/index.ftl | 8 +- 9 files changed, 344 insertions(+), 35 deletions(-) create mode 100644 generator-web/src/main/resources/templates/code-generator/ui/layui-edit.ftl create mode 100644 generator-web/src/main/resources/templates/code-generator/ui/layui-list.ftl diff --git a/README.md b/README.md index 18162f6e..97131d3b 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ |更新日期|更新内容| |-|-| +|20200306|1.提交一套layuimini+mybatisplus的模板. 2.修复mybatisplus一些相关问题. | |20200206|1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@Column带name参数(感谢@liuyu-struggle的建议) 3.去除mybatis模板中的方括号[]和修改模板里的类注释样式(感谢@gaohanghang的PR)| |20191229|1.修复bejson安全防护策略拦截问题(感谢@liangbintao和@1808083642的反馈) 2.优化字段名含date字符串的处理(感谢@smilexzh的反馈) 3.控制台动态输出项目访问地址(感谢@gaohanghang的提交)| |20191128|1.修复支持string-copy导致的以n结尾的字母不显示问题 2.jpa-entity新增swagger@ApiModel@ApiModelProperty注解和SQL字段@Column注解(感谢@yjq907的建议) | diff --git a/generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java b/generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java index ada0a1bf..b54673c4 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java +++ b/generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java @@ -15,16 +15,14 @@ public class ServerConfig implements ApplicationListener { private int serverPort; - - public int getPort() { - return this.serverPort; - } + private String serverPath; @Override public void onApplicationEvent(WebServerInitializedEvent event) { this.serverPort = event.getWebServer().getPort(); - //log.info("Get WebServer port {}", serverPort); - log.info("项目启动启动成功!访问地址: http://localhost:{}/generator", serverPort); + //新增动态path by zhengkai + this.serverPath = event.getApplicationContext().getApplicationName(); + log.info("项目启动启动成功!访问地址: http://localhost:{}{}", serverPort,serverPath); } } diff --git a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java b/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java index 6e601958..b6e5b60d 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java +++ b/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java @@ -30,6 +30,8 @@ public Map getResultByParams(Map params) throws result.put("swagger-ui", freemarkerTool.processString("code-generator/ui/swagger-ui.ftl", params)); result.put("element-ui", freemarkerTool.processString("code-generator/ui/element-ui.ftl", params)); result.put("bootstrap-ui", freemarkerTool.processString("code-generator/ui/bootstrap-ui.ftl", params)); + result.put("layui-edit", freemarkerTool.processString("code-generator/ui/layui-edit.ftl", params)); + result.put("layui-list", freemarkerTool.processString("code-generator/ui/layui-list.ftl", params)); //mybatis old result.put("controller", freemarkerTool.processString("code-generator/mybatis/controller.ftl", params)); result.put("service", freemarkerTool.processString("code-generator/mybatis/service.ftl", params)); diff --git a/generator-web/src/main/resources/static/version.json b/generator-web/src/main/resources/static/version.json index 4d7211c0..4316322f 100644 --- a/generator-web/src/main/resources/static/version.json +++ b/generator-web/src/main/resources/static/version.json @@ -1 +1 @@ -{"version": "20200206"} \ No newline at end of file +{"version": "20200306"} \ No newline at end of file diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl index 3686847c..ce1d9508 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl @@ -1,20 +1,28 @@ package ${packageName}.controller; +import com.alibaba.fastjson.JSON; import ${packageName}.entity.${classInfo.className}; import ${packageName}.mapper.${classInfo.className}Mapper; +import ${packageName}.util.ReturnT; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.springframework.web.servlet.ModelAndView; + +import java.util.Date; import java.util.List; import java.util.Map; /** - * @description ${classInfo.classComment} - * @author ${authorName} - * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} - */ +* @description ${classInfo.classComment} +* @author ${authorName} +* @date ${.now?string('yyyy-MM-dd HH:mm:ss')} +*/ +@Slf4j @RestController @RequestMapping("/${classInfo.className?uncap_first}") public class ${classInfo.className}Controller { @@ -26,14 +34,20 @@ public class ${classInfo.className}Controller { * 新增或编辑 */ @PostMapping("/save") - public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ - ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("id",id)) - if(${classInfo.className?uncap_first}!=null){ + public Object save(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){ + log.info("${classInfo.className?uncap_first}:"+JSON.toJSONString(${classInfo.className?uncap_first})); + ${classInfo.className} old${classInfo.className} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",${classInfo.className?uncap_first}.get${classInfo.className}Id())); + ${classInfo.className?uncap_first}.setModifyDate(new Date()); + if(old${classInfo.className}!=null){ ${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first}); }else{ - ${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first}); + if(${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_name",${classInfo.className?uncap_first}.get${classInfo.className}Name()))!=null){ + return new ReturnT<>(ReturnT.FAIL_CODE,"保存失败,名字重复"); + } + ${classInfo.className?uncap_first}.setCreateDate(new Date()); + ${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first}); } - return ${returnUtil}.success(${classInfo.className?uncap_first}); + return new ReturnT<>(ReturnT.SUCCESS_CODE,"保存成功"); } /** @@ -41,11 +55,12 @@ public class ${classInfo.className}Controller { */ @PostMapping("/delete") public Object delete(int id){ - ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("id",id)) + ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id)); if(${classInfo.className?uncap_first}!=null){ - return ${returnUtil}.success(${classInfo.className?uncap_first}); + ${classInfo.className?uncap_first}Mapper.deleteById(id); + return new ReturnT<>(ReturnT.SUCCESS_CODE,"删除成功"); }else{ - return ${returnUtil}.error("没有找到该对象"); + return new ReturnT<>(ReturnT.FAIL_CODE,"没有找到该对象"); } } @@ -54,11 +69,11 @@ public class ${classInfo.className}Controller { */ @PostMapping("/find") public Object find(int id){ - ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("id",id)) + ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id)); if(${classInfo.className?uncap_first}!=null){ - return ${returnUtil}.success(${classInfo.className?uncap_first}); + return new ReturnT<>(${classInfo.className?uncap_first}); }else{ - return ${returnUtil}.error("没有找到该对象"); + return new ReturnT<>(ReturnT.FAIL_CODE,"没有找到该对象"); } } @@ -66,17 +81,33 @@ public class ${classInfo.className}Controller { * 分页查询 */ @PostMapping("/list") - public Object list(${classInfo.className} ${classInfo.className?uncap_first}, - @RequestParam(required = false, defaultValue = "0") int pageNumber, - @RequestParam(required = false, defaultValue = "10") int pageSize) { + public Object list(String searchParams, + @RequestParam(required = false, defaultValue = "0") int page, + @RequestParam(required = false, defaultValue = "10") int limit) { + log.info("page:"+page+"-limit:"+limit+"-json:"+ JSON.toJSONString(searchParams)); //分页构造器 - Page<${classInfo.className}> page = new Page<${classInfo.className}>(pageNumber,pageSize); + Page<${classInfo.className}> buildPage = new Page<${classInfo.className}>(page,limit); //条件构造器 - QueryWrapper<${classInfo.className}> queryWrapperw = new QueryWrapper<${classInfo.className}>(${classInfo.className?uncap_first}); + QueryWrapper<${classInfo.className}> queryWrapper = new QueryWrapper<${classInfo.className}>(); + if(StringUtils.isNotEmpty(searchParams)&&JSON.isValid(searchParams)) { + ${classInfo.className} ${classInfo.className?uncap_first} = JSON.parseObject(searchParams, ${classInfo.className}.class); + queryWrapper.eq(StringUtils.isNoneEmpty(${classInfo.className?uncap_first}.get${classInfo.className}Name()), "${classInfo.className?uncap_first}_name", ${classInfo.className?uncap_first}.get${classInfo.className}Name()); + } //执行分页 - IPage<${classInfo.className}> pageList = certPersonMapper.selectPage(page, queryWrapperw); + IPage<${classInfo.className}> pageList = ${classInfo.className?uncap_first}Mapper.selectPage(buildPage, queryWrapper); //返回结果 - return ${returnUtil}.success(pageList); + return new ReturnT<>(pageList.getRecords(),Integer.parseInt(pageList.getTotal()+"")); + } + @GetMapping("/list") + public ModelAndView listPage(){ + return new ModelAndView("cms/${classInfo.className?uncap_first}-list"); + } + @GetMapping("/edit") + public ModelAndView editPage(int id){ + ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id)); + return new ModelAndView("cms/${classInfo.className?uncap_first}-edit","${classInfo.className?uncap_first}",${classInfo.className?uncap_first}); } - } + + + diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl index 231dbd5b..c34443d8 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl @@ -1,13 +1,15 @@ package ${packageName}.mapper; + import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.springframework.stereotype.Repository; +import org.apache.ibatis.annotations.Mapper; +import ${packageName}.entity.${classInfo.className}; /** * @description ${classInfo.classComment} * @author ${authorName} * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} */ -@Repository +@Mapper public interface ${classInfo.className}Mapper extends BaseMapper<${classInfo.className}> { diff --git a/generator-web/src/main/resources/templates/code-generator/ui/layui-edit.ftl b/generator-web/src/main/resources/templates/code-generator/ui/layui-edit.ftl new file mode 100644 index 00000000..cac62d75 --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/ui/layui-edit.ftl @@ -0,0 +1,78 @@ + + + + + layuimini + + + + + + + + +
+ + + +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> + <#list classInfo.fieldList as fieldItem > +
+ +
+ + <#--${fieldItem.fieldComment}--> +
+
+ + + +
+
+ +
+
+
+
+ + + + \ No newline at end of file diff --git a/generator-web/src/main/resources/templates/code-generator/ui/layui-list.ftl b/generator-web/src/main/resources/templates/code-generator/ui/layui-list.ftl new file mode 100644 index 00000000..f5b7b842 --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/ui/layui-list.ftl @@ -0,0 +1,195 @@ + + + + + layuimini + + + + + + + +
+
+ +
+ 搜索信息 +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+ + + +
+ + + + +
+
+ + + + + + \ 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 eb151fe2..63dd94f7 100644 --- a/generator-web/src/main/resources/templates/index.ftl +++ b/generator-web/src/main/resources/templates/index.ftl @@ -88,7 +88,7 @@ success: function (data) { if (data.code === 200) { codeData = data.data; - genCodeArea.setValue(codeData.entity); + genCodeArea.setValue(codeData.beetlentity); genCodeArea.setSize('auto', 'auto'); $.toast("√ 代码生成成功"); //添加历史记录 @@ -231,7 +231,7 @@
返回封装
- +
包名路径
@@ -329,7 +329,7 @@ CREATE TABLE 'userinfo' ( -