mybtis-plus代码生成器
pom导入依赖
<mybatis-plus.version>3.5.1</mybatis-plus.version>
<velocity.version>2.3</velocity.version>
<swagger.version>2.7.0</swagger.version>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<!-- velocity 模板引擎, Mybatis Plus 代码生成器需要 -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>${velocity.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
测试类代码运行
void generator(){
FastAutoGenerator.create("jdbc:mysql://localhost:3306/blb_edu?serverTimezone=GMT%2B8", "root", "root")
.globalConfig(builder -> {
builder.author("xl")
.enableSwagger()
.disableOpenDir()
.fileOverride()
.outputDir(System.getProperty("user.dir")+"/src/main/java");
})
.packageConfig(builder -> {
builder.parent(this.getClass().getPackage().getName().substring(0, this.getClass().getPackage().getName().lastIndexOf(".")))
.moduleName(this.getClass().getPackage().getName().split("\\.")[2])
.entity("entity")
.service("service")
.serviceImpl("service.impl")
.controller("controller")
.mapper("mapper")
.xml("mapper")
.pathInfo(Collections.singletonMap(OutputFile.mapperXml,System.getProperty("user.dir")+"/src/main/java/"+this.getClass().getPackage().getName().replace(".","/")+"/mapper"));
})
.strategyConfig(builder -> {
builder.entityBuilder().enableLombok()
.addTableFills(new Column("gmtCreate", FieldFill.INSERT))
.addTableFills(new Property("updatedTime", FieldFill.INSERT_UPDATE));
builder.mapperBuilder().enableMapperAnnotation().build();
builder.controllerBuilder().enableHyphenStyle()
.enableRestStyle();
builder
.addTablePrefix("edu_")
.serviceBuilder()
.formatServiceFileName("%sService")
.formatServiceImplFileName("%sServiceImpl")
.entityBuilder()
.enableChainModel()
.enableLombok()
.enableRemoveIsPrefix()
.logicDeleteColumnName("is_deleted")
.logicDeletePropertyName("deleted")
.enableTableFieldAnnotation()
.controllerBuilder()
.formatFileName("%sController")
.enableRestStyle()
.mapperBuilder()
.enableBaseResultMap()
.superClass(BaseMapper.class)
.formatMapperFileName("%sMapper")
.enableMapperAnnotation()
.formatXmlFileName("%sMapper");
})
.execute();
}