MyBatisPlus 在3.0.3版本之前使用代码生成器因为存在默认依赖,所以不需要其他的依赖,项目中使用的是3.0.1的版本,所以不用添加其他依赖,添加之后反倒是会报错,实际上MP官网上已经说明了这一点,只是自己没注意才出现错误

3.0.3版本之后就需要添加如下依赖

<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.1</version>
</dependency>

MP默认将Velocity作为模板引擎,同时也支持FreemarkerBeetl 需要替换参看链接

这里贴一个比较简单的代码生成器代码

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; public class CodeGeneration { /**
*
* @Title: main
* @Description: 生成
* @param args
*/
public static void main(String[] args) {
AutoGenerator mpg = new AutoGenerator(); // 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir("D:\\generation");//输出文件路径
gc.setFileOverride(true); // 是否文件覆盖
gc.setActiveRecord(false);// 不需要ActiveRecord(实体类继承Model)特性的请改为false
gc.setEnableCache(false);// XML 二级缓存
gc.setBaseResultMap(true);// XML ResultMap
gc.setBaseColumnList(true);// XML ColumnList
gc.setAuthor("lizhan");// 作者 // 自定义文件命名,注意 %s 会自动填充表实体属性!
gc.setControllerName("%sController");
// 默认service接口名IXXXService 自定义指定之后就不会用I开头了
gc.setServiceName("%sService");
gc.setServiceImplName("%sServiceImpl");
gc.setMapperName("%sMapper");
gc.setXmlName("%sMapper");
mpg.setGlobalConfig(gc); // 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL);
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("xxx");
dsc.setPassword("xxx");
dsc.setUrl("jdbc:mysql://localhost:3306/xxx");
mpg.setDataSource(dsc); // 策略配置
StrategyConfig strategy = new StrategyConfig();
// strategy.setTablePrefix(new String[] { "sys_" });// 此处可以修改为您的表前缀
strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略(下划线转驼峰)
strategy.setInclude("user"); // 需要生成的表名 strategy.setSuperServiceClass(null);
strategy.setSuperServiceImplClass(null);
strategy.setSuperMapperClass(null); mpg.setStrategy(strategy); // 包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.xxx");
pc.setController("controller");
pc.setService("service");
pc.setServiceImpl("impl");
pc.setMapper("mapper");
pc.setEntity("entity");
pc.setXml("xml");
mpg.setPackageInfo(pc); // 执行生成
mpg.execute(); } }

MybatisPlus使用代码生成器遇到的小问题的更多相关文章

  1. SpringBoot之【mybatisplus】代码生成器

    1.概述. AutoGenerator 是 MyBatis-Plus 的代码生成器,通过 AutoGenerator 可以快速生成 Entity.Mapper.Mapper XML.Service.C ...

  2. mybatis-plus的代码生成器

    简介:构建自定义mybatis-plus模板,自动生成mybatis,entity,mapper,service,controller 项目源码:https://github.com/y369q369 ...

  3. 3、SpringBoot+MybatisPlus整合-------代码生成器

    <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</art ...

  4. 小书MybatisPlus第7篇-代码生成器的原理精讲及使用方法

    本文是本系列文章的第七篇,前6篇访问地址如下: 小书MybatisPlus第1篇-整合SpringBoot快速开始增删改查 小书MybatisPlus第2篇-条件构造器的应用及总结 小书Mybatis ...

  5. MyBatis-Plus学习笔记(2):代码生成器

    AutoGenerator 是 MyBatis-Plus 的代码生成器,通过 AutoGenerator 可以快速生成 Entity.Mapper.Mapper XML.Service.Control ...

  6. Mybatis-Plus代码生成器使用详解

    首先创建springboot的项目(创建步骤省略) 创建好项目后要配置maven依赖,附上pom.xml: <?xml version="1.0" encoding=&quo ...

  7. MyBatis-Plus使用(1)-概述+代码生成器

    MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发.提高效率而生. 官网:https://mp.baomidou.com ...

  8. Mybatis-Plus的填坑之路 - Lynwood/wunian7yulian

    目录 Mybatis-Plus 我来填坑~ 目录 一.简单介绍 官方说明 : 成绩: 最新版本: 开发层面MyBatis-Plus特色 Mybatis-Plus中的Plus 二.MP的特性 三.MP框 ...

  9. SpringBoot学习笔记(十七:MyBatis-Plus )

    @ 目录 一.MyBatis-Plus简介 二.基本用法 1.准备数据 2.引入依赖 2.配置 3.代码 4.测试 三.自定义SQL 1.自定义批量插入 2.自定义查询 2.1.自定义返回结果 2.2 ...

随机推荐

  1. AtomicInteger例子

    AtomicInteger可以保证原子性,可见性,有序性 public class AtomicIntegerTest { private static AtomicInteger value = n ...

  2. 使用jedis操作redis常用方法

    在redis入门及在商城案例中的使用中简单介绍了下使用jedis如何操作redis,但是其实方法是跟redis的操作大部分是相对应的.我这里做下记录 1.String类型操作 public class ...

  3. Linux下安装Python3.6.8并安装包

    一.问题在Linux下面安装Python3.6.8,由于在Linux中的Python是2.7.x的版本因此,我们需要在Linux中新下载一个Python 二.解决1.python的安装(1)下载包利用 ...

  4. SQL Server使用sp_executesql在存储过程中执行多个批处理

    SQL Server中有些SQL语句只能在一个批处理里面完成,例如CREATE SCHEMA语句创建SCHEMA的时候,每个SCHEMA都需要在一个单独的批处理里面完成: CREATE SCHEMA ...

  5. WPF ObservableCollection,INotifyPropertyChanged

    xaml: <DockPanel Margin="10">                <StackPanel DockPanel.Dock="Rig ...

  6. 监控微信小程序中的慢HTTP请求

    摘要: 请求时间太长,影响用户体验,使用 Fundebug 监控慢请求. Fundebug 的微信小程序监控插件在 0.5.0 版本已经支持监控 HTTP 请求错误,在小程序中通过wx.request ...

  7. vue多个路由使用同一个页面,通过name判断参数,渲染页面数据

    项目中,发现有多个页面的数据内容相同,只是请求数据的参数不同,就可以使用同一个组件来渲染 这里的客户列表 / 我负责的 / 我参与的 都使用同一个组件,不同点在请求数据的参数 可以看到,通过钩子函数, ...

  8. idea万能快捷键,不可不知的17个实用技巧

    说明 IDEA里有一个万能快捷键(alt enter),功能非常强大,同一个快捷键,可以根据不同的语境提示你不同的操作,很多人可能还不了解这些功能,在处理代码的时候还手动处理,了解这些技巧之后,你编码 ...

  9. Java中的equals与==

    package demo; public class Test { public static void main(String[] args) { String str1 = new String( ...

  10. Elasticasearch Web管理工具-Cerebro

    cerebro是一个使用Scala,Play Framework,AngularJS和Bootstrap构建的开源(MIT许可)elasticsearch web管理工具.需要Java 1.8或更高版 ...