From e8baf8bfd4b891a02a3bcfa6677de3c99d061602 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 2 Aug 2023 20:51:07 +0800 Subject: [PATCH 1/6] =?UTF-8?q?build:=20=E5=85=B6=E4=BB=96=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E6=94=B9=E5=88=B0=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mybatis-flex-codegen/pom.xml | 42 ++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/mybatis-flex-codegen/pom.xml b/mybatis-flex-codegen/pom.xml index 4749cfd7..2b002144 100644 --- a/mybatis-flex-codegen/pom.xml +++ b/mybatis-flex-codegen/pom.xml @@ -20,16 +20,16 @@ - - org.mybatis - mybatis - - - com.mybatis-flex - mybatis-flex-spring + mybatis-flex-core ${mybatis-flex.version} + + + com.mybatis-flex + mybatis-flex-processor + + @@ -99,6 +99,7 @@ swagger-annotations 1.6.11 true + test @@ -112,10 +113,37 @@ org.springframework spring-web ${spring.version} + true test + + com.mybatis-flex + mybatis-flex-spring + ${mybatis-flex.version} + + + com.mybatis-flex + mybatis-flex-core + + + true + test + + + com.mybatis-flex + mybatis-flex-solon-plugin + ${mybatis-flex.version} + + + com.mybatis-flex + mybatis-flex-core + + + true + test + From 45ac3a39b4b88e9a7f2fe1ccdc2f791e6f4ec4e5 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 2 Aug 2023 20:53:51 +0800 Subject: [PATCH 2/6] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codegen/config/ServiceImplConfig.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ServiceImplConfig.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ServiceImplConfig.java index 59c1858d..3eafaf45 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ServiceImplConfig.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ServiceImplConfig.java @@ -15,9 +15,6 @@ */ package com.mybatisflex.codegen.config; -import com.mybatisflex.spring.service.impl.CacheableServiceImpl; -import com.mybatisflex.spring.service.impl.ServiceImpl; - /** * 生成 ServiceImpl 的配置。 * @@ -40,7 +37,7 @@ public class ServiceImplConfig { /** * 自定义 ServiceImpl 的父类。 */ - private Class superClass = ServiceImpl.class; + private Class superClass; /** * 是否覆盖之前生成的文件。 @@ -53,10 +50,16 @@ public class ServiceImplConfig { private boolean cacheExample; public String buildSuperClassImport() { + if (superClass == null) { + return "com.mybatisflex.spring.service.impl.ServiceImpl"; + } return superClass.getName(); } public String buildSuperClassName() { + if (superClass == null) { + return "ServiceImpl"; + } return superClass.getSimpleName(); } @@ -124,7 +127,7 @@ public class ServiceImplConfig { * 是否生成缓存例子。 */ public boolean isCacheExample() { - return CacheableServiceImpl.class.equals(superClass) && cacheExample; + return cacheExample; } /** @@ -135,4 +138,4 @@ public class ServiceImplConfig { return this; } -} \ No newline at end of file +} From eadb8a32c917fe4c2180ebf7396b7b2bd05f023c Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 2 Aug 2023 20:54:06 +0800 Subject: [PATCH 3/6] =?UTF-8?q?style:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codegen/config/StrategyConfig.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/StrategyConfig.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/StrategyConfig.java index 105343f8..d27b6ea1 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/StrategyConfig.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/StrategyConfig.java @@ -95,7 +95,7 @@ public class StrategyConfig { ignoreColumns = new HashSet<>(); } for (String column : columns) { - if (column != null && column.trim().length() > 0) { + if (column != null && !column.trim().isEmpty()) { ignoreColumns.add(column.trim().toLowerCase()); } } @@ -103,19 +103,14 @@ public class StrategyConfig { } /** - * 设置要生成的模式 - * - * @return + * 设置要生成的模式。 */ public String getGenerateSchema() { return generateSchema; } /** - * 获取要生成的模式 - * - * @param generateSchema - * @return + * 获取要生成的模式。 */ public StrategyConfig setGenerateSchema(String generateSchema) { this.generateSchema = generateSchema; @@ -209,7 +204,7 @@ public class StrategyConfig { } for (String table : tables) { - if (table != null && table.trim().length() > 0) { + if (table != null && !table.trim().isEmpty()) { generateTables.add(table.trim()); } } @@ -226,7 +221,7 @@ public class StrategyConfig { } for (String table : tables) { - if (table != null && table.trim().length() > 0) { + if (table != null && !table.trim().isEmpty()) { unGenerateTables.add(table.trim()); } } From 3d5e73b59d65bb17f04c956b00caa20686bd765a Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 2 Aug 2023 20:54:35 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20=E5=86=85=E7=BD=AE=20serviceImpl-So?= =?UTF-8?q?lon=20=E6=A8=A1=E6=9D=BF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/enjoy/serviceImpl-Solon.tpl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 mybatis-flex-codegen/src/main/resources/templates/enjoy/serviceImpl-Solon.tpl diff --git a/mybatis-flex-codegen/src/main/resources/templates/enjoy/serviceImpl-Solon.tpl b/mybatis-flex-codegen/src/main/resources/templates/enjoy/serviceImpl-Solon.tpl new file mode 100644 index 00000000..5b8a8f7c --- /dev/null +++ b/mybatis-flex-codegen/src/main/resources/templates/enjoy/serviceImpl-Solon.tpl @@ -0,0 +1,18 @@ +package #(packageConfig.serviceImplPackage); + +import com.mybatisflex.solon.service.impl.ServiceImpl; +import #(packageConfig.entityPackage).#(table.buildEntityClassName()); +import #(packageConfig.mapperPackage).#(table.buildMapperClassName()); +import #(packageConfig.servicePackage).#(table.buildServiceClassName()); +import org.noear.solon.annotation.ProxyComponent; + +/** + * #(table.getComment()) 服务层实现。 + * + * @author #(javadocConfig.getAuthor()) + * @since #(javadocConfig.getSince()) + */ +@ProxyComponent +public class #(table.buildServiceImplClassName()) extends ServiceImpl<#(table.buildMapperClassName()), #(table.buildEntityClassName())> implements #(table.buildServiceClassName()) { + +} From b089c0824f33687402564e7b2364b98e06d6cd85 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 2 Aug 2023 20:55:10 +0800 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20serviceImpl-So?= =?UTF-8?q?lon=20=E6=A8=A1=E6=9D=BF=E5=B8=B8=E9=87=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mybatisflex/codegen/constant/TemplateConst.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/constant/TemplateConst.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/constant/TemplateConst.java index f2a929d2..b41b2545 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/constant/TemplateConst.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/constant/TemplateConst.java @@ -31,9 +31,10 @@ public final class TemplateConst { public static final String MAPPER = "/templates/enjoy/mapper.tpl"; public static final String SERVICE = "/templates/enjoy/service.tpl"; public static final String SERVICE_IMPL = "/templates/enjoy/serviceImpl.tpl"; + public static final String SERVICE_IMPL_SOLON = "/templates/enjoy/serviceImpl-Solon.tpl"; public static final String CONTROLLER = "/templates/enjoy/controller.tpl"; public static final String TABLE_DEF = "/templates/enjoy/tableDef.tpl"; public static final String MAPPER_XML = "/templates/enjoy/mapperXml.tpl"; public static final String PACKAGE_INFO = "/templates/enjoy/package-info.tpl"; -} \ No newline at end of file +} From 682355fc7258fbfb531105868060336bf3c7ab81 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 2 Aug 2023 20:55:36 +0800 Subject: [PATCH 6/6] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=20serviceImpl-So?= =?UTF-8?q?lon=20=E6=A8=A1=E6=9D=BF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codegen/test/GeneratorTest.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/GeneratorTest.java b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/GeneratorTest.java index e8891d4e..0da555d0 100644 --- a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/GeneratorTest.java +++ b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/GeneratorTest.java @@ -21,7 +21,7 @@ import com.mybatisflex.codegen.config.ColumnConfig; import com.mybatisflex.codegen.config.GlobalConfig; import com.mybatisflex.codegen.config.TableConfig; import com.mybatisflex.codegen.config.TableDefConfig; -import com.mybatisflex.spring.service.impl.CacheableServiceImpl; +import com.mybatisflex.codegen.constant.TemplateConst; import com.zaxxer.hikari.HikariDataSource; import org.junit.Test; @@ -132,7 +132,7 @@ public class GeneratorTest { globalConfig.enableService(); //配置生成 serviceImpl globalConfig.enableServiceImpl() - .setSuperClass(CacheableServiceImpl.class) +// .setSuperClass(CacheableServiceImpl.class) .setCacheExample(true); //配置生成 controller globalConfig.enableController(); @@ -228,7 +228,7 @@ public class GeneratorTest { @Test public void testCodeGen4() { - //配置数据源 + // 配置数据源 HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8"); dataSource.setUsername("root"); @@ -236,31 +236,40 @@ public class GeneratorTest { GlobalConfig globalConfig = new GlobalConfig(); - //用户信息表,用于存放用户信息。 -> 用户信息 + // 用户信息表,用于存放用户信息。 -> 用户信息 UnaryOperator tableFormat = (e) -> e.split(",")[0].replace("表", ""); - //设置注解生成配置 + // 设置注解生成配置 globalConfig.getJavadocConfig() .setAuthor("王帅") .setTableCommentFormat(tableFormat); - //设置生成文件目录和根包 + // 设置生成文件目录和根包 globalConfig.getPackageConfig() .setSourceDir(System.getProperty("user.dir") + "/src/test/java") .setMapperXmlPath(System.getProperty("user.dir") + "/src/test/resources/mapper") .setBasePackage("com.test"); - //设置表前缀和只生成哪些表 + // 设置模板路径 + globalConfig.getTemplateConfig() + .setServiceImpl(TemplateConst.SERVICE_IMPL_SOLON); + + // 设置表前缀和只生成哪些表 globalConfig.getStrategyConfig() .setTablePrefix("sys_") .setGenerateTable("sys_user"); - //配置生成 entity + // 配置生成 entity globalConfig.enableEntity() .setOverwriteEnable(true) .setWithLombok(false) .setWithActiveRecord(true); + // 配置生成 service + globalConfig.enableMapper(); + globalConfig.enableService(); + globalConfig.enableServiceImpl(); + //通过 datasource 和 globalConfig 创建代码生成器 Generator generator = new Generator(dataSource, globalConfig);