复制就可用:
public class CodeGenerator {
public static void main(String[] args) {
String url = "jdbc:mysql:///sss";
String username = "root";
String password = "123456";
String moduleName = "sys";
String mapperLocation = "D:\\IDEA2023\\mall\\src\\main\\resources\\mapper\\" + moduleName;//根据resources的绝对路径修改,新的要重新修改
String tables = "address,admin,category,product,productimage,productorder,productorderitem,property,propertyvalue,review,user";//所关联的数据库所有表名,新表需重新写
FastAutoGenerator.create(url, username, password)//新的需要重新修改
.globalConfig(builder -> {
builder.author("jzj") // 设置作者
//.enableSwagger() // 开启 swagger 模式
//.fileOverride() // 覆盖已生成文件
.outputDir("D:\\IDEA2023\\mall\\src\\main\\java"); // 指定输出目录,根据需求修改
})
.packageConfig(builder -> {
builder.parent("com.jzj") // 设置父包名,尽量跟自己给项目主父类名一样
.moduleName(moduleName) // 设置父包模块名
.pathInfo(Collections.singletonMap(OutputFile.xml, mapperLocation)); // 设置mapperXml生成路径
})
.strategyConfig(builder -> {
builder.addInclude(tables) // 设置需要生成的表名
.addTablePrefix("_x","_c"); // 设置过滤表前缀,有需要可以过滤前缀
})
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
}
}