MybatisPlus(十二) 代码生成器

一、代码生成器

public class FastAutoGeneratorTest {

        public static void main(String[] args) {
            FastAutoGenerator
                            //数据库信息
                            .create("jdbc:mysql://127.0.0.1:3306/gao? characterEncoding=utf-8&userSSL=false", "root", "root")
                            //全局配置
                            .globalConfig(builder -> {
                                builder.author("atguigu") // 设置作者
                                        .enableSwagger() // 开启 swagger 模式
                                        .fileOverride() // 覆盖已生成文件
                                        .outputDir("D://mybatis_plus"); // 指定输出目录
                            })
                            //包配置
                            .packageConfig(builder -> {
                                builder.parent("com.gao") // 设置父包名
                                        .moduleName("mybatisplus") // 设置父包模块名
                                        .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://mybatis_plus")); // 设置mapperXml生成路径
                            })
                            //策略配置
                            .strategyConfig(builder -> {
                                builder.addInclude("t_user") // 设置需要生成的数据库表名
                                        .addTablePrefix("t_", "c_"); // 设置去掉过滤表前缀
                            })
                            //模板引擎
                            .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker 引擎模板,默认的是Velocity引擎模板
                            .execute();
        }


}

 

二、结果

com.gao.mybatisPlus
    |--controller
    |--service
    |--dao
    |--entity
XXXMapper.xml

 

posted @ 2023-03-12 20:49  向大海  阅读(16)  评论(0编辑  收藏  举报