- 一、导入所需依赖
- 二、实现代码
- 三、效果如下
PS:MybatisPlus的代码生成器,可以根据数据库的表,一键生成对应的controller、entity、mapper、service以及对应的Mapper.xml文件 一、导入所需依赖
二、实现代码com.baomidou mybatis-plus-generator 3.5.1 org.freemarker freemarker 2.3.31
package com.vector.springbootmabatisplus;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.util.Collections;
public class FastAutoGeneratorTest {
public static void main(String[] args) {
FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/mybatis_plus?characterEncoding=utf-8&userSSL=false", "数据库用户名", "数据库密码")
.globalConfig(builder -> {
builder.author("vector")// 设置作者
//.enableSwagger() // 开启 swagger 模式
.fileOverride() // 覆盖已生成文件
.outputDir("D://mybatis_plus");// 指定输出目录
}).packageConfig(builder -> {
builder.parent("com.vector")// 设置父包名
.moduleName("mybatisplus")// 设置父包模块名
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://mybatis_plus"));// 设置mapperXml生成路径
})
.strategyConfig(builder -> {
builder.addInclude("t_user")// 设置需要生成的表名
.addTablePrefix("t_", "c_");// 设置过滤表前缀
}).templateEngine(new FreemarkerTemplateEngine())// 使用Freemarker 引擎模板,默认的是Velocity引擎模板
.execute();
}
}
三、效果如下



