import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import java.util.Collections;
public class Generator {
public static void main(String[] args) {
Generator();
}
private static void Generator() {
FastAutoGenerator.create("jdbc:mysql://localhost:3306/music", "root", "123456")
.globalConfig(builder -> {
builder.author("yunge").disableOpenDir() // 设置作者
.outputDir("D:\\java\\music\\src\\main\\java"); // 指定输出目录
})
.packageConfig(builder -> {
builder.parent("com.yunge.music") // 设置父包名
.moduleName("") // 设置父包模块名
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:\\java\\music\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
})
.strategyConfig(builder -> {
builder.addInclude("admin") // 设置需要生成的表名
.addTablePrefix("t_", "sys_")//开启lombok// 设置过滤表前缀
.entityBuilder().enableLombok();//开启lombok
})
// .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
}
}
依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3</version>
</dependency>