1.添加依赖。
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.5.3.1</version> <scope>test</scope> </dependency>
2.创建类
public class MyBatisGenerator {
@Test
public void generator(){
String url= "jdbc:mysql://localhost:3306/yshop?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai";
String username= "root";
String password= "root";
FastAutoGenerator.create(url,username,password)
.globalConfig(builder -> {
builder.author("ZhanJiang") //设置作者
// .enableSwagger() //开启swagger模式
.fileOverride() //覆盖已生成的文件
.outputDir("C:\\Users\\NIYEYE\\Desktop\\out"); //指定输出的目录
})
.packageConfig(builder -> {
builder.parent("com.example.yshopmall.content") //设置父包名
// .moduleName("system") //设置父包模块名
.pathInfo(Collections.singletonMap(OutputFile.xml,"C:\\Users\\NIYEYE\\Desktop\\out")); //设置mapperXml文件生成路径
})