mybatis-plus 代码生成器
1.添加依赖
<dependency> <groupId>com.baomidougroupId> <artifactId>mybatis-plus-generatorartifactId> <version>3.5.1version> dependency> <dependency> <groupId>com.baomidougroupId> <artifactId>mybatis-plus-boot-starterartifactId> <version>3.4.3.4version> dependency> <dependency> <groupId>org.freemarkergroupId> <artifactId>freemarkerartifactId> <version>2.3.31version> dependency>
2.代码
public class MybatisPlusCodeGenerator { private static final String url = ""; private static final String username = ""; private static final String password = ""; private static final String bao = "com.ever"; private static final String module = "orm"; private static final String output = "D://Code//"; public static void main(String[] args) { String[] tableNames = {"user"}; MybatisPlusCodeGenerator.execute(tableNames); } public static void execute(String[] tableNames){ FastAutoGenerator.create(url, username, password) .globalConfig(builder -> { builder.author("lz") // 设置作者 //.enableSwagger() // 开启 swagger 模式 .fileOverride() // 覆盖已生成文件 .outputDir(output); // 指定输出目录 }) .packageConfig(builder -> { builder.parent(bao) // 设置父包名 .moduleName(module) // 设置父包模块名 .pathInfo(Collections.singletonMap(OutputFile.mapperXml, output)); // 设置mapperXml生成路径 }) .strategyConfig(builder -> { builder.addInclude(tableNames) // 设置需要生成的表名 .addTablePrefix(); // 设置过滤表前缀 }) .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板 .execute(); } }