新建一个类
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.util.HashMap;
import java.util.Map;
public class MpGenerator {
private static final DataSourceConfig DATA_SOURCE_CONFIG = new DataSourceConfig
.Builder("jdbc:mysql://", "username", "password")
.build();
private static StrategyConfig.Builder strategyConfig() {
return new StrategyConfig.Builder()
.addInclude("table1,table2");
}
private static GlobalConfig.Builder globalConfig() {
return new GlobalConfig.Builder().fileOverride();
}
private static PackageConfig.Builder packageConfig() {
return new PackageConfig.Builder();
}
public static void main(String[] args) {
AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
generator.strategy(
strategyConfig().addTablePrefix("t_", "c_")
.mapperBuilder()
.enableBaseColumnList()
.enableBaseResultMap()
.enableMapperAnnotation()
.controllerBuilder()
.enableHyphenStyle()
.enableRestStyle()
.build()
);
generator.global(globalConfig()
.author("")
.commentDate("yyyy-MM-dd")
.outputDir("C:**\\src\\main\\java\\")
.disableOpenDir()
.build()
);
Map<OutputFile, String> pathInfo = new HashMap<>();
pathInfo.put(OutputFile.xml, "C:**\\src\\main\\resources\\mapper");
pathInfo.put(OutputFile.entity, "C:**\\src\\main\\java\\com\\goodwill\\hdr\\entity");
generator.packageInfo(packageConfig().pathInfo(pathInfo)
.parent("com.demo.demo")
.moduleName("demo")
.build());
generator.execute(new FreemarkerTemplateEngine());
}
}
添加依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
|