mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
!229 feat:内置 serviceImpl-Solon 模板用于切换
Merge pull request !229 from 王帅/main
This commit is contained in:
commit
47887fdbfe
@ -20,16 +20,16 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring</artifactId>
|
||||
<artifactId>mybatis-flex-core</artifactId>
|
||||
<version>${mybatis-flex.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
@ -99,6 +99,7 @@
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.6.11</version>
|
||||
<optional>true</optional>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@ -112,10 +113,37 @@
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring</artifactId>
|
||||
<version>${mybatis-flex.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<optional>true</optional>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-solon-plugin</artifactId>
|
||||
<version>${mybatis-flex.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<optional>true</optional>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ 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";
|
||||
|
||||
@ -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()) {
|
||||
|
||||
}
|
||||
@ -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();
|
||||
@ -250,6 +250,10 @@ public class GeneratorTest {
|
||||
.setMapperXmlPath(System.getProperty("user.dir") + "/src/test/resources/mapper")
|
||||
.setBasePackage("com.test");
|
||||
|
||||
// 设置模板路径
|
||||
globalConfig.getTemplateConfig()
|
||||
.setServiceImpl(TemplateConst.SERVICE_IMPL_SOLON);
|
||||
|
||||
// 设置表前缀和只生成哪些表
|
||||
globalConfig.getStrategyConfig()
|
||||
.setTablePrefix("sys_")
|
||||
@ -261,6 +265,11 @@ public class GeneratorTest {
|
||||
.setWithLombok(false)
|
||||
.setWithActiveRecord(true);
|
||||
|
||||
// 配置生成 service
|
||||
globalConfig.enableMapper();
|
||||
globalConfig.enableService();
|
||||
globalConfig.enableServiceImpl();
|
||||
|
||||
//通过 datasource 和 globalConfig 创建代码生成器
|
||||
Generator generator = new Generator(dataSource, globalConfig);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user