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
+
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
+}
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());
}
}
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
+}
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()) {
+
+}
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);