1. 创建一个空的maven或springboot项目,添加依赖
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
2. 编写配置主程序类
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import java.util.Collections;
public class Test {
public static void main(String[] args) {
FastAutoGenerator.create("jdbc:mysql://74.94.8.81:3306/gulimall_pms", "root", "root")
.globalConfig(builder -> {
builder.author("ljs") // 设置作者
.enableSwagger() // 开启 swagger 模式
.fileOverride() // 覆盖已生成文件
.outputDir("F:\\project\\java\\springCloud\\test_generator\\aaa"); // 指定输出目录
})
.packageConfig(builder -> {
builder.parent("com.baomidou.mybatisplus.samples.generator") // 设置父包名
.moduleName("system") // 设置父包模块名
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "F:\\project\\java\\springCloud\\test_generator\\aaa")); // 设置mapperXml生成路径
})
.strategyConfig(builder -> {
builder.addInclude("pms_attr") // 设置需要生成的表名
.addTablePrefix("t_", "c_"); // 设置过滤表前缀
})
.execute();
}
}
3. 运行主程序类,代码生成结束