mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
commit
bd07f4665f
@ -56,6 +56,11 @@ public class EntityConfig {
|
||||
*/
|
||||
private boolean withLombok;
|
||||
|
||||
/**
|
||||
* 实体类数据源。
|
||||
*/
|
||||
private String dataSource;
|
||||
|
||||
/**
|
||||
* 获取类前缀。
|
||||
*/
|
||||
@ -146,4 +151,19 @@ public class EntityConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实体类数据源。
|
||||
*/
|
||||
public String getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置实体类数据源。
|
||||
*/
|
||||
public EntityConfig setDataSource(String dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@ -877,6 +877,20 @@ public class GlobalConfig {
|
||||
getEntityConfig().setWithLombok(entityWithLombok);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityConfig#getDataSource()
|
||||
*/
|
||||
public String getEntityDataSource() {
|
||||
return getEntityConfig().getDataSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityConfig#setDataSource(String)
|
||||
*/
|
||||
public void setEntityDataSource(String dataSource) {
|
||||
getEntityConfig().setDataSource(dataSource);
|
||||
}
|
||||
|
||||
public boolean isMapperGenerateEnable() {
|
||||
return mapperGenerateEnable;
|
||||
}
|
||||
@ -1248,28 +1262,28 @@ public class GlobalConfig {
|
||||
/**
|
||||
* @see TableDefConfig#getPropertiesNameStyle()
|
||||
*/
|
||||
public TableDefConfig.NameStyle getPropertiesNameStyle() {
|
||||
public TableDefConfig.NameStyle getTableDefPropertiesNameStyle() {
|
||||
return getTableDefConfig().getPropertiesNameStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TableDefConfig#setPropertiesNameStyle(TableDefConfig.NameStyle)
|
||||
*/
|
||||
public void setPropertiesNameStyle(TableDefConfig.NameStyle propertiesNameStyle) {
|
||||
public void setTableDefPropertiesNameStyle(TableDefConfig.NameStyle propertiesNameStyle) {
|
||||
getTableDefConfig().setPropertiesNameStyle(propertiesNameStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TableDefConfig#getInstanceSuffix()
|
||||
*/
|
||||
public String getInstanceSuffix() {
|
||||
public String getTableDefInstanceSuffix() {
|
||||
return getTableDefConfig().getInstanceSuffix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TableDefConfig#setInstanceSuffix(String)
|
||||
*/
|
||||
public void setInstanceSuffix(String instanceSuffix) {
|
||||
public void setTableDefInstanceSuffix(String instanceSuffix) {
|
||||
getTableDefConfig().setInstanceSuffix(instanceSuffix);
|
||||
}
|
||||
|
||||
|
||||
@ -223,6 +223,12 @@ public class Table {
|
||||
tableAnnotation.append(", schema = \"").append(globalSchema).append("\"");
|
||||
}
|
||||
|
||||
// 添加 dataSource 配置,因为代码生成器是一个数据源生成的,所以这些实体类应该都是一个数据源。
|
||||
String dataSource = globalConfig.getEntityDataSource();
|
||||
if (StringUtil.isNotBlank(dataSource)) {
|
||||
tableAnnotation.append(", dataSource = \"").append(dataSource).append("\"");
|
||||
}
|
||||
|
||||
if (tableConfig != null) {
|
||||
if (StringUtil.isNotBlank(tableConfig.getSchema())) {
|
||||
tableAnnotation.append(", schema = \"").append(tableConfig.getSchema()).append("\"");
|
||||
|
||||
@ -23,6 +23,7 @@ import com.mybatisflex.codegen.config.TableConfig;
|
||||
import com.mybatisflex.codegen.config.TableDefConfig;
|
||||
import com.mybatisflex.spring.service.impl.CacheableServiceImpl;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
@ -148,7 +149,7 @@ public class GeneratorTest {
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void testCodeGen3() {
|
||||
//配置数据源
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
@ -200,6 +201,7 @@ public class GeneratorTest {
|
||||
// 配置生成 entity
|
||||
globalConfig.enableEntity()
|
||||
.setOverwriteEnable(true)
|
||||
.setDataSource("ds1")
|
||||
.setWithLombok(true);
|
||||
|
||||
// 配置生成 mapper
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user