From 19a39169c7d4e42f0e8eaa706d1036071aa203e2 Mon Sep 17 00:00:00 2001 From: wangbing Date: Mon, 20 May 2019 15:37:27 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E9=9D=9E=E6=A0=87?= =?UTF-8?q?=E5=87=86=E8=A1=A8=E7=BB=93=E6=9E=84=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manger/callable/SpringBootCallable.java | 20 ++-- .../xyz/wbsite/dbtool/javafx/po/Table.java | 14 +-- .../SpringBoot/java/mgr/managerImpl.ftl | 7 +- .../SpringBoot/java/mpr/mapper_nosys.ftl | 100 ++++++++++++++++++ .../java/rsp/createResponseClass.ftl | 2 + .../SpringBoot/resources/application-dev.ftl | 2 +- .../modules/SpringBoot/test/test.ftl | 11 +- 7 files changed, 140 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/modules/SpringBoot/java/mpr/mapper_nosys.ftl diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java index 200b9f1b..4bafbe65 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java @@ -38,7 +38,7 @@ public class SpringBootCallable implements Callable { dBmapper = ProjectManager.dBmapper; // 创建项目文件夹 - File projectDir = new File(root , project.getProjectName()); + File projectDir = new File(root, project.getProjectName()); if (!projectDir.exists()) { projectDir.mkdir(); } else { @@ -298,10 +298,10 @@ public class SpringBootCallable implements Callable { // } for (Table table : md.getTables()) { for (Field field : table.getFields()) { - if ("Enum".equals(field.getFieldType().javaType())){ - ctx.put("Type",field.getCName()); + if ("Enum".equals(field.getFieldType().javaType())) { + ctx.put("Type", field.getCName()); ctx.put("FieldComment", field.getFieldComment()); - freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), field.getCName()+".java"), option + "/java/enums/Type.ftl", ctx); + freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), field.getCName() + ".java"), option + "/java/enums/Type.ftl", ctx); } } } @@ -332,7 +332,12 @@ public class SpringBootCallable implements Callable { for (Table table : md.getTables()) { ctx.put("table", table); freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".java"), option + "/java/mpr/mapperJava.ftl", ctx); - freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/mpr/mapper.ftl", ctx); + + if (md.isHasSysFields()) { + freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/mpr/mapper.ftl", ctx); + } else { + freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/mpr/mapper_nosys.ftl", ctx); + } } } @@ -345,6 +350,7 @@ public class SpringBootCallable implements Callable { HashMap ctx = new HashMap(); ctx.put("tool", Tool.class); + ctx.put("module", md); ctx.put("basePackage", md.getProjectBasePackage()); ctx.put("moduleName", md.getModuleName()); ctx.put("author", md.getProjectAuthor()); @@ -360,7 +366,6 @@ public class SpringBootCallable implements Callable { freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Manager" + ".java"), option + "/java/mgr/manager.ftl", ctx); freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "ManagerImpl" + ".java"), option + "/java/mgr/managerImpl.ftl", ctx); } - } /** @@ -378,6 +383,7 @@ public class SpringBootCallable implements Callable { HashMap ctx = new HashMap(); ctx.put("tool", Tool.class); + ctx.put("module", md); ctx.put("basePackage", md.getProjectBasePackage()); ctx.put("moduleName", md.getModuleName()); ctx.put("author", md.getProjectAuthor()); @@ -434,6 +440,7 @@ public class SpringBootCallable implements Callable { HashMap ctx = new HashMap(); ctx.put("tool", Tool.class); + ctx.put("module", md); ctx.put("basePackage", md.getProjectBasePackage()); ctx.put("moduleName", md.getModuleName()); ctx.put("author", md.getProjectAuthor()); @@ -745,6 +752,7 @@ public class SpringBootCallable implements Callable { HashMap ctx = new HashMap(); ctx.put("tool", Tool.class); + ctx.put("module", md); ctx.put("basePackage", md.getProjectBasePackage()); ctx.put("moduleName", md.getModuleName()); ctx.put("table", table); diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/po/Table.java b/src/main/java/xyz/wbsite/dbtool/javafx/po/Table.java index d7119653..1417da02 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/po/Table.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/po/Table.java @@ -131,7 +131,7 @@ public class Table extends TreeItem { } public Boolean getCreate() { - return create; + return create || !dBhandle.isHasSysFields(); } public void setCreate(Boolean create) { @@ -139,7 +139,7 @@ public class Table extends TreeItem { } public Boolean getDelete() { - return delete; + return delete || !dBhandle.isHasSysFields(); } public void setDelete(Boolean delete) { @@ -147,7 +147,7 @@ public class Table extends TreeItem { } public Boolean getUpdate() { - return update; + return update || !dBhandle.isHasSysFields(); } public void setUpdate(Boolean update) { @@ -155,7 +155,7 @@ public class Table extends TreeItem { } public Boolean getFind() { - return find; + return find || !dBhandle.isHasSysFields(); } public void setFind(Boolean find) { @@ -163,7 +163,7 @@ public class Table extends TreeItem { } public Boolean getGet() { - return get; + return get && dBhandle.isHasSysFields(); } public void setGet(Boolean get) { @@ -171,7 +171,7 @@ public class Table extends TreeItem { } public Boolean getSearch() { - return search; + return search && dBhandle.isHasSysFields(); } public void setSearch(Boolean search) { @@ -179,7 +179,7 @@ public class Table extends TreeItem { } public Boolean getGetAll() { - return getAll; + return getAll && dBhandle.isHasSysFields(); } public void setGetAll(Boolean getAll) { diff --git a/src/main/resources/modules/SpringBoot/java/mgr/managerImpl.ftl b/src/main/resources/modules/SpringBoot/java/mgr/managerImpl.ftl index ab50a40e..515efbcc 100644 --- a/src/main/resources/modules/SpringBoot/java/mgr/managerImpl.ftl +++ b/src/main/resources/modules/SpringBoot/java/mgr/managerImpl.ftl @@ -47,17 +47,22 @@ public class ${table.getCName()}ManagerImpl implements ${table.getCName()}Manage return response; } + <#if module.isHasSysFields()> long id = IDgenerator.nextId(); - ${table.getCName()} entity = MapperUtil.map(request, ${table.getCName()}.class); entity.setId(id); + <#else> + ${table.getCName()} entity = MapperUtil.map(request, ${table.getCName()}.class); + long result = ${table.getFName()}Mapper.insert(entity, token); if (1L != result) { response.addError(ErrorType.BUSINESS_ERROR, Message.CREATE_FAILURE); return response; } + <#if module.isHasSysFields()> response.setId(id); + return response; } diff --git a/src/main/resources/modules/SpringBoot/java/mpr/mapper_nosys.ftl b/src/main/resources/modules/SpringBoot/java/mpr/mapper_nosys.ftl new file mode 100644 index 00000000..ae72ad62 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/mpr/mapper_nosys.ftl @@ -0,0 +1,100 @@ + + + + + +<#if dataBase == 'ORACLE'> + "${module.modulePrefix?default("")}${table.tableName}" +<#elseif dataBase='MYSQL'> + `${module.modulePrefix?default("")}${table.tableName}` + + + + <#if dataBase == 'ORACLE'> + <#list table.fields as f>"${f.fieldName}"<#if f_has_next>, + <#elseif dataBase='MYSQL'> + <#list table.fields as f>`${f.fieldName}`<#if f_has_next>, + + + + + <#list table.fields as f> + + + + + + + + INSERT INTO + + ( + + ) + VALUES + ( + <#list table.fields as f> + ${r"#{"}request.${f.getFName()},jdbcType=${f.fieldType.jdbcType()}}<#if f_has_next>, + + ) + + + + DELETE FROM + + WHERE + 1 = 2 + + + + UPDATE + + SET + <#if dataBase == 'ORACLE'> + <#list table.fields as f> + "${f.fieldName}" = ${r"#{"}request.${f.getFName()},jdbcType=${f.fieldType.jdbcType()}}<#if f_has_next>, + + <#elseif dataBase='MYSQL'> + <#list table.fields as f> + `${f.fieldName}` = ${r"#{"}request.${f.getFName()},jdbcType=${f.fieldType.jdbcType()}}<#if f_has_next>, + + + WHERE + 1 = 2 + + \ No newline at end of file diff --git a/src/main/resources/modules/SpringBoot/java/rsp/createResponseClass.ftl b/src/main/resources/modules/SpringBoot/java/rsp/createResponseClass.ftl index 847d39ea..d5627fb2 100644 --- a/src/main/resources/modules/SpringBoot/java/rsp/createResponseClass.ftl +++ b/src/main/resources/modules/SpringBoot/java/rsp/createResponseClass.ftl @@ -11,6 +11,7 @@ import ${basePackage}.frame.base.BaseResponse; */ public class ${table.getCName()}CreateResponse extends BaseResponse { + <#if module.isHasSysFields()> /** * ID */ @@ -23,4 +24,5 @@ public class ${table.getCName()}CreateResponse extends BaseResponse { public void setId(Long id) { this.id = id; } + } diff --git a/src/main/resources/modules/SpringBoot/resources/application-dev.ftl b/src/main/resources/modules/SpringBoot/resources/application-dev.ftl index 2e59ca60..ed6f8e9a 100644 --- a/src/main/resources/modules/SpringBoot/resources/application-dev.ftl +++ b/src/main/resources/modules/SpringBoot/resources/application-dev.ftl @@ -4,7 +4,7 @@ server.servlet.context-path=/ spring.mvc.static-path-pattern=/static/** spring.resources.static-locations=classpath:static/ spring.application.name=${projectName} -spring.main.banner-mode=on +spring.main.banner-mode=CONSOLE spring.devtools.restart.enabled=true <#if cloud> eureka.client.serviceUrl.defaultZone=http://localhost:18080/eureka/ diff --git a/src/main/resources/modules/SpringBoot/test/test.ftl b/src/main/resources/modules/SpringBoot/test/test.ftl index e6710907..c2746f9a 100644 --- a/src/main/resources/modules/SpringBoot/test/test.ftl +++ b/src/main/resources/modules/SpringBoot/test/test.ftl @@ -61,11 +61,17 @@ public class ${table.getCName()}Test { ${table.getCName()}CreateResponse createResponse = ${table.getFName()}Manager.create(createRequest,token); +<#if module.isHasSysFields()> assertTrue(!createResponse.hasError() && createResponse.getId() > 0); - +<#else> + assertTrue(!createResponse.hasError()); + //删除数据 ${table.getCName()}DeleteRequest request = new ${table.getCName()}DeleteRequest(); + <#if module.isHasSysFields()> request.setId(createResponse.getId()); + <#else> + ${table.getCName()}DeleteResponse response = ${table.getFName()}Manager.delete(request,token); @@ -88,7 +94,10 @@ public class ${table.getCName()}Test { //更新数据 ${table.getCName()}UpdateRequest request = new ${table.getCName()}UpdateRequest(); +<#if module.isHasSysFields()> request.setId(createResponse.getId()); +<#else> + <#list table.fields as field> <#if !field.isSystem> request.${field.setterName()}(${field.getTestValue()});