mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
commit
79bf1da59f
@ -1,4 +1,4 @@
|
|||||||
# Active Record
|
# Active Record <Badge type="tip" text="v1.5.3" />
|
||||||
|
|
||||||
[Active Record 模式](http://www.martinfowler.com/eaaCatalog/activeRecord.html)出自 Martin Fowler
|
[Active Record 模式](http://www.martinfowler.com/eaaCatalog/activeRecord.html)出自 Martin Fowler
|
||||||
写的《[企业应用架构模式](https://book.douban.com/subject/4826290/)》书中。在 Active Record
|
写的《[企业应用架构模式](https://book.douban.com/subject/4826290/)》书中。在 Active Record
|
||||||
|
|||||||
@ -45,11 +45,10 @@ public class EnjoyTemplate implements ITemplate {
|
|||||||
e.addSharedStaticMethod(StringUtil.class);
|
e.addSharedStaticMethod(StringUtil.class);
|
||||||
e.setSourceFactory(new FileAndClassPathSourceFactory());
|
e.setSourceFactory(new FileAndClassPathSourceFactory());
|
||||||
});
|
});
|
||||||
|
// 以下配置将支持 user.girl 表达式去调用 user 对象的 boolean isGirl() 方法
|
||||||
|
Engine.addFieldGetterToFirst(new FieldGetters.IsMethodFieldGetter());
|
||||||
}
|
}
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
|
|
||||||
// 以下配置将支持 user.girl 表达式去调用 user 对象的 boolean isGirl() 方法
|
|
||||||
Engine.addFieldGetterToFirst(new FieldGetters.IsMethodFieldGetter());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import com.mybatisflex.codegen.config.TableConfig;
|
|||||||
import com.mybatisflex.codegen.config.TableDefConfig;
|
import com.mybatisflex.codegen.config.TableDefConfig;
|
||||||
import com.mybatisflex.spring.service.impl.CacheableServiceImpl;
|
import com.mybatisflex.spring.service.impl.CacheableServiceImpl;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ public class GeneratorTest {
|
|||||||
generator.generate();
|
generator.generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
public void testCodeGen3() {
|
public void testCodeGen3() {
|
||||||
//配置数据源
|
//配置数据源
|
||||||
HikariDataSource dataSource = new HikariDataSource();
|
HikariDataSource dataSource = new HikariDataSource();
|
||||||
@ -157,6 +158,13 @@ public class GeneratorTest {
|
|||||||
dataSource.setUsername("root");
|
dataSource.setUsername("root");
|
||||||
dataSource.setPassword("12345678");
|
dataSource.setPassword("12345678");
|
||||||
|
|
||||||
|
//通过 datasource 和 globalConfig 创建代码生成器
|
||||||
|
new Generator(dataSource, globalConfig()).generate();
|
||||||
|
new Generator(dataSource, globalConfig()).generate();
|
||||||
|
new Generator(dataSource, globalConfig()).generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private GlobalConfig globalConfig() {
|
||||||
GlobalConfig globalConfig = new GlobalConfig();
|
GlobalConfig globalConfig = new GlobalConfig();
|
||||||
|
|
||||||
//用户信息表,用于存放用户信息。 -> 用户信息
|
//用户信息表,用于存放用户信息。 -> 用户信息
|
||||||
@ -215,11 +223,7 @@ public class GeneratorTest {
|
|||||||
.setOverwriteEnable(true)
|
.setOverwriteEnable(true)
|
||||||
.setMapperAnnotation(true);
|
.setMapperAnnotation(true);
|
||||||
|
|
||||||
//通过 datasource 和 globalConfig 创建代码生成器
|
return globalConfig;
|
||||||
Generator generator = new Generator(dataSource, globalConfig);
|
|
||||||
|
|
||||||
//开始生成代码
|
|
||||||
generator.generate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user