mybatis-plus Generator 代码生成器

public class CodeGenerator {

    final static String projectPath = System.getProperty("user.dir") + "/apis/src/main/java";

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入表名,多个英文逗号分隔?所有输入 all");

        String tablesStr = null;
        if (scan.hasNext()) {
            tablesStr = scan.next();
        }
        scan.close();

        List tables = "all".equals(tablesStr) ? Collections.emptyList() : Arrays.asList(tablesStr.split(","));

        FastAutoGenerator builder = builder(tables);
        builder.execute();

    }

    private static FastAutoGenerator builder(List tables) {
        return FastAutoGenerator.create("jdbc:mysql://192.168.137.133:3306/nacos_config?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&serverTimezone=Asia/Shanghai&useSSL=false", "root", "abcd!234")
                .globalConfig(builder -> {
                    builder.author("ButiF")// 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir(projectPath); // 指定输出目录

                })
                //  包名配置
                .packageConfig(builder -> {
                    builder.parent("com.cloud.butif.apis").entity("domain");

                })
                //实体策略配置
                .strategyConfig(builder -> {
                    builder.entityBuilder()
                            //开启Lombok,默认生成@Get,@Set,可以手动换成@Data
                            .enableColumnConstant()
                            .enableTableFieldAnnotation()
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .enableLombok();
                })
                //控制类策略配置
                .strategyConfig(builder -> {
                    builder.controllerBuilder()
                            .enableHyphenStyle()
                            .enableRestStyle()
                            .formatFileName("%sController");
                })
                //服务类策略配置
                .strategyConfig(builder -> {
                    builder.serviceBuilder()
                            .formatServiceFileName("%sService")
                            .formatServiceImplFileName("%sServiceImp");
                })
                //  策略配置   包含/排除
                .strategyConfig(builder -> {
                    builder.addInclude(tables);
                })
                // 使用Freemarker引擎模板,默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine());
    }

}


         
        
            com.baomidou
            mybatis-plus-boot-starter
        
        
            com.baomidou
            mybatis-plus-generator
         
        
            org.freemarker
            freemarker
        

        
        
            org.projectlombok
            lombok
        

        
        
            io.springfox
            springfox-swagger2
        
        
            io.springfox
            springfox-swagger-ui
        

        
        
            com.github.xiaoymin
            knife4j-spring-boot-starter
        
        
            org.springframework.boot
            spring-boot-starter-validation
        

你可能感兴趣的:(mybatis-plus Generator 代码生成器)