一、添加和mybatisPlus相关的依赖
二、创建代码生成器类
package com.example.mybatisplus_generator.generator;import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;public class CodeGenerator {static final String URL = "jdbc:mysql://172.16.156.133:3306/test?characterEncoding=utf-8&serverTimezone=Asia/Shanghai";public static void main(String[] args) {String projectPath = System.getProperty("user.dir");String outputDir = projectPath + "/src/main/java";System.out.println(outputDir);FastAutoGenerator.create(URL, "root", "123456MQL")//全局配置.globalConfig(builder ->//设置作者builder.author("MQL")//开启 swagger 模式.enableSwagger()// 覆盖已生成文件//.fileOverride()//指定输出目录.outputDir(outputDir)).packageConfig(builder ->// 设置父包名builder.parent("com.example.mybatisplus_generator")// 设置父包模块名.moduleName("dyxQutation")// 设置mapperXml生成路径//.pathInfo(Collections.singletonMap(OutputFile.xml, "D://"))//策略配置.strategyConfig(builder -> builder.addInclude("my_student"))//使用Freemarker引擎模板,默认的是Velocity引擎模板.templateEngine(new FreemarkerTemplateEngine())//执行.execute();}
}
三、运行上面类中的main方法,自动生成剪头所指
四、解决
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
五、添加mybatis和spring需要的映射接口类扫描目录
六、依次在mapper、service、controller中添加接口代码.....