MybatisPlus自动生成代码
import com.baomidou.mybatisplus.generator.FastAutoGenerator;import com.baomidou.mybatisplus.generator.config.OutputFile;
import java.util.Collections;
public class MyBatisPlusGenerator {
public static void main(String[] args) {
String url = "数据库链接";
String username = "数据库账号";
String password = "数据库密码";
String author = "作者";
String outputJavaDir = "f:\\demo\\src\\main\\java";
String outputXmlDir = "f:\\demo\\src\\main\\resources\\mapper";
String parentPackageName = "com.demo";//父包名
FastAutoGenerator.create(url, username, password)
.globalConfig(builder -> {
builder.author(author) // 设置作者
.enableSwagger() // 开启 swagger 模式
.outputDir(outputJavaDir); // 指定输出目录
})
.packageConfig(builder -> {
builder.parent(parentPackageName)// 设置父包名
.pathInfo(Collections.singletonMap(OutputFile.xml, outputXmlDir)); // 设置mapperXml生成路径
})
.strategyConfig(builder -> {
builder.addInclude("weather_info"); // 设置需要生成的表名
builder.entityBuilder().enableLombok(); // 使用 Lombok
builder.controllerBuilder().enableRestStyle(); // 使用 RestController
builder.serviceBuilder().formatServiceFileName("%sService"); // Service 接口命名格式
builder.entityBuilder().formatFileName("%sDO"); //实体类文件名命名格式
builder.mapperBuilder().enableBaseResultMap();
builder.mapperBuilder().enableBaseColumnList();
builder.mapperBuilder().enableMapperAnnotation();
})
.execute();
}
页:
[1]