mybatis mybatis-plus-generator+clickhouse自动生成代码案例详解

时间:2021-12-28 01:18:00

mybatis-plus-generator + clickhouse 自动生成代码

依赖

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!--> mybatis-plus </!-->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.4.3.1</version>
</dependency>
 
<!--> 代码模板 </!-->
<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
</dependency>
 
<!--> mybatis-plus代码生成器 </!-->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-generator</artifactId>
    <version>3.5.0</version>
</dependency>

配置

?
1
2
3
4
5
6
mybatis-plus:
    configuration:
        map-underscore-to-camel-case: true
        auto-mapping-behavior: full
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
        mapper-locations: classpath*:mapper/**/*Mapper.xml

CodeGenerator

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class CodeGenerator {
 
    private static final String REPLACE_LOCAL_PATH = "/target/test-classes/";
    private static final String JAVA_PATH = "/src/main/java";
    public static void main(String[] args) {
 
        // 获取项目路径
        String projectPath = ClassLoader.getSystemResource("").getPath().replace(REPLACE_LOCAL_PATH, "");
        // 全局配置
        GlobalConfig gc = GeneratorBuilder.globalConfigBuilder()
                .fileOverride().openDir(false)
                .outputDir(projectPath + JAVA_PATH)
                .author("generator")
                .enableSwagger()
                .commentDate("yyyy-MM-dd").build();
 
 
        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig.Builder("jdbc:clickhouse://ip:port", "user", "password")
                .dbQuery(new ClickHouseQuery()).schema("schema").build();
 
 
        // 包配置
        PackageConfig pc = GeneratorBuilder.packageConfigBuilder().parent("com.study.clickhouse").build();
 
        // 策略配置
        StrategyConfig strategy = GeneratorBuilder.strategyConfigBuilder()
                .addInclude("table_name")
                .addTablePrefix(pc.getModuleName() + "_")
                .controllerBuilder().enableHyphenStyle()
                .entityBuilder()
                .naming(NamingStrategy.underline_to_camel)
                .columnNaming(NamingStrategy.underline_to_camel)
                .versionColumnName("version").logicDeleteColumnName("isDelete")
                .enableLombok()
                .build();
 
        TemplateConfig templateConfig = GeneratorBuilder.templateConfigBuilder().build();
 
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator(dsc).global(gc).strategy(strategy).template(templateConfig).packageInfo(pc);
 
 
        mpg.execute(new FreemarkerTemplateEngine());
 
    }
}

click相关参考

到此这篇关于mybatis mybatis-plus-generator+clickhouse自动生成代码案例详解的文章就介绍到这了,更多相关mybatis mybatis-plus-generator+clickhouse自动生成代码内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/zhb890306/article/details/119994860