代码生成器
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.4</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
package com.fp.wms.config;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class MybatisGeneratorConfig {
public static void main(String[] args) {
generate();
}
protected static List<String> getTables(String tables) {
return "all".equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
}
private static void generate() {
FastAutoGenerator.create("jdbc:mysql://localhost:3306/wms?serverTimezone=UTC", "root", "123456")
.globalConfig(builder -> {
builder.author("fp")
.fileOverride()
.outputDir("D:\\ProgramData\\ideaProject\\springboot-wms\\src\\main\\java\\");
})
.packageConfig(builder -> {
builder.parent("com.fp.wms")
.moduleName("")
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:\\ProgramData\\ideaProject\\springboot-wms\\src\\main\\resources\\mapper\\"));
})
.strategyConfig((scanner, builder) -> builder.addInclude(getTables(scanner.apply("请输入表名,多个英文逗号分隔?所有输入 all")))
.controllerBuilder().enableRestStyle()
.entityBuilder().enableLombok()
.mapperBuilder().enableMapperAnnotation()
)
.templateEngine(new FreemarkerTemplateEngine())
.execute();
}
}