mybatis mybatis-plus-generator+clickhouse自動生成代碼案例詳解

mybatis-plus-generator + clickhouse 自動生成代碼

依賴

		<!--> 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>

配置

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

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自動生成代碼內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: