1、引入相关依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</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>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<version>3.4.3</version>
</dependency>
2、编写生成代码
FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/liukx",
"root", "zxc.10086")
.globalConfig(builder -> {
builder.author("liukx") // 设置作者
.enableSwagger() // 开启 swagger 模式
.fileOverride() // 覆盖已生成文件
.outputDir("E://code//Generator//src//main//java"); // 指定输出目录
})
.packageConfig(builder -> {
builder.parent("com.liukx") // 设置父包名
.moduleName("generator") // 设置父包模块名
.pathInfo(Collections.singletonMap(OutputFile.mapper, "E://code//Generator//src//main//java//com//liukx//generator//mapper")); // 设置mapperXml生成路径
})
.strategyConfig(builder -> {
builder.addInclude("sys_user") // 设置需要生成的表名
.addTablePrefix("t_", "c_"); // 设置过滤表前缀
})
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
3、补全Swagger依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/244627.html