mybatis-plus代码生成器
public class MyBatisPlusGenerator {
public static void main(String[] args) throws SQLException {
//1. 全局配置
GlobalConfig config = new GlobalConfig();
config.setActiveRecord(true) // 是否支持AR模式
.setAuthor("zuo") // 作者
.setOutputDir("F:\\stsworkspace\\src\\main\\java") // 生成路径
.setFileOverride(true) // 文件覆盖
// .setIdType(IdType.AUTO) // 主键策略
.setServiceName("%sService") // 设置生成的service接口的名字的首字母是否为I
// IEmployeeService
.setBaseResultMap(true)//生成基本的resultMap
.setBaseColumnList(true);//生成基本的SQL片段
//2. 数据源配置
DataSourceConfig dsConfig = new DataSourceConfig();
dsConfig.setDbType(DbType.MYSQL) // 设置数据库类型
.setDriverName("com.mysql.cj.jdbc.Driver")
.setUrl("jdbc:mysql://localhost:3306/demo?useUnicode=true&useSSL=false&serverTimezone=UTC")
.setUsername("root")
.setPassword("root");
//3. 策略配置globalConfiguration中
StrategyConfig stConfig = new StrategyConfig();
stConfig.setCapitalMode(true) //全局大写命名
.setDbColumnUnderline(true) // 指定表名 字段名是否使用下划线
.setNaming(NamingStrategy.underline_to_camel) // 数据库表映射到实体的命名策略
//.setTablePrefix("tbl_")
.setInclude(new String[]{"user"}); // 生成的表
// //4. 包名策略配置
// PackageConfig pkConfig = new PackageConfig();
// pkConfig.setParent("com.imooc")
// .setMapper("dao")//dao
// .setService("service")//servcie
// .setController("controller")//controller
// .setEntity("entity")
// .setXml("mapper");//mapper.xml
//4. 包名策略配置
PackageConfig pkConfig = new PackageConfig();
StrategyConfig sc=new StrategyConfig();
pkConfig.setParent("com.imooc")
.setMapper("dao")//dao
.setService("service")//servcie
.setController("controller")//controller
.setEntity("entity")
.setXml("resource");//mapper.xml
//5. 整合配置
AutoGenerator ag = new AutoGenerator();
ag.setGlobalConfig(config)
.setDataSource(dsConfig)
.setStrategy(stConfig)
.setPackageInfo(pkConfig);
//6. 执行
ag.execute();
}
}
加入依赖包
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>2.3</version>
</dependency>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- 日志 -->
<!-- 实现slf4j接口并整合 -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.1</version>
</dependency>
<!-- 数据库 -->
<!-- c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<!-- MP 代码生成工具需要的依赖1 velocity-engine-core 2 slf4j-api 3slf4j-log4j12 -->
<!-- Apache velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
<!-- sfl4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.9-rc</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>2.1.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
mybatis-plus代码生成器的更多相关文章
- 0120 springboot集成Mybatis和代码生成器
在日常开发中,数据持久技术使用的架子使用频率最高的有3个,即spring-jdbc , spring-jpa, spring-mybatis.详情可以看我之前的一篇文章spring操作数据库的3个架子 ...
- mybatis自定义代码生成器(Generator)——自动生成model&dao代码
花了两天的时间研究了下mybatis的generator大体了解了其生成原理以及实现过程.感觉generator做的非常不错,给开发者也留足了空间.看完之后在generator的基础上实现了自定义的生 ...
- 想做时间管理大师?你可以试试Mybatis Plus代码生成器
1. 前言 对于写Crud的老司机来说时间非常宝贵,一些样板代码写不但费时费力,而且枯燥无味.经常有小伙伴问我,胖哥你怎么天天那么有时间去搞新东西,透露一下秘诀呗. 好吧,今天就把Mybatis-pl ...
- mybatis(mysql)代码生成器扩展
前些天在做我的KSF框架的时候需要用到mybatis代码生成器, 但是发现有一些东西需要调整,主要集中在以下几点: 1. 加入batchInsert 2. 加入batchUpdate 3. mysq ...
- 手把手教你Spring Boot整合Mybatis Plus 代码生成器
一.在pom.xml中添加所需依赖 <!-- MyBatis-Plus代码生成器--> <dependency> <groupId>com.baomidou< ...
- 寻找写代码感觉(五)之Mybatis官方代码生成器的使用
一.Mybatis Generator生成器 见名知意,官方给出的代码生成器.好处就是不用自己写实体类.接口.xml文件了,应对简单增删改查是可以的.复杂的还是需要自己手写sql的. 二.Mybati ...
- mybatis maven 代码生成器(mysql)
pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...
- Spring boot + mybatis + mysql代码生成器
引入依赖: 在pom文件最下边: <build> <plugins> <!--逆向工程--> <plugin> <groupId>org.m ...
- Spring boot + mybatis + oracle代码生成器
在pom文件中加入依赖: <build> <plugins> <!--逆向工程--> <plugin> <groupId>org.mybat ...
- mybatis generator代码生成器的使用
一.有关mybatis generator的使用可以查看如下网址:http://www.mybatis.org/generator/index.html 二.如下是我自己整理的学习步骤: <1& ...
随机推荐
- 本学期c#学习总结
本学期c#学习总结 时间转瞬即逝,大一上半学期的学习生涯已经结束.虽然以前我没什么关于学习计算机的基础,但是经过了这几个月的学习我也还是有点收获的. 我发现c#语言的关键词有很多语言特性和固定的用法, ...
- App后台Keynote
[App后台Keynote] 一.基础. 1.一个 节省 流量 的 处理 方法 是 让 App 下载 经过 压缩 的 图片( 一般 是 几十 KB 以下), 当 用户 需要 查看 原图 时 才 下载 ...
- echarts仪表盘
echarts链接:https://gallery.echartsjs.com/editor.html?c=xkasbcOqh0 代码: var axislineColor = new echarts ...
- [leetcode]243. Shortest Word Distance最短单词距离
Given a list of words and two words word1 and word2, return the shortest distance between these two ...
- IntelliJ IDEA常用快捷键(Mac)
Mac 键盘符号和修饰键说明 ⌘ ——> Command ⇧ ——> Shift ⌥ ——> Option ⌃ ——> Control ↩︎ ——> Return/Ent ...
- node.js中使用 http-proxy 创建代理服务器
代理,也称网络代理,是一种特殊网络服务,允许一个终端通过代理服务与另一个终端进行非直接的连接,这样利于安全和防止被攻击. 代理服务器,就是代理网络用户去获取网络信息,就是信息的中转,负责转发. 代理又 ...
- uboot——git代码仓
1,注册GitHub帐号,创建GitHub项目代码仓库 https://www.cnblogs.com/LoTGu/p/6075994.html 参考其第二段,注册账号,设置仓库. 2,上传代码 测试 ...
- Django model进阶
Django-model进阶 QuerySet 可切片 使用Python 的切片语法来限制查询集记录的数目 .它等同于SQL 的LIMIT 和OFFSET 子句. >>> Ent ...
- charles本地调试之map和rewrite功能
charles是一款mac下代理调试工具,对于前端开发同学来说是相当方便的一个调试接口的工具:不过charles需要收费,不过在天朝几乎收费的软件都能找到破解方法: 使用charles前,需要将cha ...
- 通过Solr所提供的Dataimporthandler实现数据源的导入
如需要使用到Solr中的dataimporthandler增量导入功能,则还需要引入两个所依赖的jar包,在上一篇随笔中所提到的下载的Solr项目文件solr-4.10.3\dist目录下可以找到所依 ...