官网:https://baomidou.com/pages/779a6e/
依赖文件
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.2</version>
</dependency>
<!-- freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
生成代码
public class codeGenerate {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/admin_system";
String username = "root";
String password = "liuyang";
String tables = "x_user,x_role,x_menu,x_user_role,x_role_menu";
String prefix_tables = "x_"; // 设置过滤表前缀
String moduleName = "sys"; // 设置需要生成的表名
// 父包名
String parent = "com.thexb";
// 项目路径
String projectPath = "D:\\\\FullStack\\\\admin_system\\\\back\\\\src\\\\main\\\\java";
// 设置mapperXml生成路径
String mapperLocation = "D:\\\\FullStack\\\\admin_system\\\\back\\\\src\\\\main\\\\resources\\\\mapper\\\\" + moduleName;
FastAutoGenerator.create(url, username, password)
.globalConfig(builder -> {
builder.author("thexb") // 设置作者
// .enableSwagger() // 开启 swagger 模式
// .fileOverride() // 覆盖已生成文件
.outputDir(projectPath); // 指定输出目录
})
.packageConfig(builder -> {
builder.parent(parent)
.moduleName(moduleName)
.pathInfo(Collections.singletonMap(OutputFile.xml, mapperLocation));
})
.strategyConfig(builder -> {
builder.addInclude(tables)
.addTablePrefix(prefix_tables);
})
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
}
}