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


<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
<!-- 添加代码生成器的依赖 -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>


开发工具:STS
代码下载链接:Github管理代码
版本:
Springboot:1.5.14.RELEASE
使用2.0以上的Springboot,会报出一些异常。欢迎知道异常原因的大牛解惑。
MybatisPlus:2.3
生成规则请参考:生成规则
前言:
我用过最方便的代码生成器、而且功能真的强大!
构建代码生成器:
1.添加依赖:
(1)代码生成器依赖
(2)Lombok依赖
使用lombok可以减少代码的开发
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
<!-- 添加代码生成器的依赖 -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
2.编写生成器:
package com.xm; import org.junit.Test; import com.baomidou.mybatisplus.enums.IdType;
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.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; public class MpGenerator { @Test
public void create() { String tableName = "user"; /**
* 配置:
* 1.全局配置
* 2.数据源配置
* 3.策略配置
* 4.包名策略配置
* 5.整合配置
*/ //1.全局配置
GlobalConfig globalConfig = new GlobalConfig();
globalConfig
//设置代码生成路径
.setOutputDir("F:\\xm\\springboot\\Springboot_MybatisPlus\\src\\main\\java")
//设置作者
.setAuthor("xm")
//设置二级缓存的开闭
.setEnableCache(false)
//设置数据库id自增
.setIdType(IdType.AUTO)
//设置覆盖更新
.setFileOverride(true)
//设置去I
.setServiceName("%sService")
//设置生产结果映射map
.setBaseResultMap(true); //2.数据源配置
DataSourceConfig dataSourceConfig = new DataSourceConfig();
dataSourceConfig
//设置数据库类型
.setDbType(DbType.MYSQL)
.setUrl("jdbc:mysql://10.1.51.31:3306/xm?useSSL=true")
.setUsername("root")
.setPassword("cube1501")
.setDriverName("com.mysql.jdbc.Driver"); //3.策略配置
StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig
//开启全局大写命名
.setCapitalMode(true)
//开启下划线转换
.setDbColumnUnderline(true)
//开启驼峰命名
.setNaming(NamingStrategy.underline_to_camel)
.setEntityLombokModel(true)
.setInclude(tableName); //4.包名策略配置
PackageConfig packageConfig = new PackageConfig();
packageConfig
.setParent("com.xm")
.setController("controller")
.setEntity("pojo")
.setMapper("mapper")
.setService("service")
.setServiceImpl("service.impl")
.setXml("mapper.xml"); //5.整合配置
AutoGenerator autoGenerator = new AutoGenerator();
autoGenerator
.setGlobalConfig(globalConfig)
.setDataSource(dataSourceConfig)
.setStrategy(strategyConfig)
.setPackageInfo(packageConfig); autoGenerator.execute(); } }
3.测试运行:

2018-07-19
3、SpringBoot+MybatisPlus整合-------代码生成器的更多相关文章
- 2、SpringBoot+MybatisPlus整合-------BaseCRUD
开发工具:STS 代码下载链接:GitHub管理代码 版本: Springboot:1.5.14.RELEASE 使用2.0以上的Springboot,会报出一些异常.欢迎知道异常原因的大牛解惑. M ...
- SpringBoot+Mybatis-Plus整合Sharding-JDBC5.1.1实现单库分表【全网最新】
一.前言 小编最近一直在研究关于分库分表的东西,前几天docker安装了mycat实现了分库分表,但是都在说mycat的bug很多.很多人还是倾向于shardingsphere,其实他是一个全家桶,有 ...
- SpringBoot+MyBatisPlus整合时提示:Invalid bound statement(not found):**.dao.UserDao.queryById
场景 在使用SpringBoot+MyBatisPlus搭建后台启动项目时,使用EasyCode自动生成代码. 在访问后台接口时提示: Invilid bound statement (not fou ...
- 1、SpringBoot+MybatisPlus整合
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...
- SpringBoot Mybatis-Plus 整合 dynamic-datasource-spring-boot-starter 对数据库进行读写分离
准备工作 对 MySql 进行主从搭建 引入 dynamic-datasource-spring-boot-starter 坐标 引入 druid-spring-boot-starter 坐标 对应框 ...
- SpringBoot系列——MyBatis-Plus整合封装
前言 MyBatis-Plus是一款MyBatis的增强工具(简称MP),为简化开发.提高效率,但我们并没有直接使用MP的CRUD接口,而是在原来的基础上封装一层通用代码,单表继承我们的通用代码,实现 ...
- SpringBoot+Mybatis+MybatisPlus整合实现基本的CRUD操作
SpringBoot+Mybatis+MybatisPlus整合实现基本的CRUD操作 1> 数据准备 -- 创建测试表 CREATE TABLE `tb_user` ( `id` ) NOT ...
- SpringBoot之【mybatisplus】代码生成器
1.概述. AutoGenerator 是 MyBatis-Plus 的代码生成器,通过 AutoGenerator 可以快速生成 Entity.Mapper.Mapper XML.Service.C ...
- SpringBoot&MyBatisPlus
5. SpringBoot 学习目标: 掌握基于SpringBoot框架的程序开发步骤 熟练使用SpringBoot配置信息修改服务器配置 基于SpringBoot完成SSM整合项目开发 5.1 入门 ...
随机推荐
- IE7+ 浏览器兼容预览本地图片
css #preview_fake { filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale); o ...
- Unity 游戏对象的组件列表
描述: 1 个游戏对象,上面有 4 个组件, 如图: 脚本 Test_01 的内容,如下: using System.Collections; using System.Collections.Gen ...
- 怎么为android控件边缘添加阴影
为控件设置一个有阴影感的背景图片即可,可以使用shape 在自定义shape中增加一层或多层,并错开,即可显示阴影效果.为增加立体感,按钮按下的时候,只设置一层.我们可以通过top, bottom, ...
- http学习笔记(三):报文
三.报文 目录: 3.1方法 1.get 2.head 3.put 4.post 5.trace 6.options 7.delete 3.2状态码 ...
- 在cms以及kindeditor中插入百度动态地图的方法
想在网页中插入动态地图不难,直接打开网址http://api.map.baidu.com/lbsapi/creatmap/,然后按照提示操作,最终生成脚本,放到html文件中即可.而在kindedit ...
- DEDE列表页和内容页调用顶级栏目ID的方法
dede模板中添加顶级栏目id的方法总结,使用dede顶级栏目id可以实现很多功能.比如,在每个列表页调用不同的栏目图片(同一顶级栏目调用相同的图片),如果我们做N个栏目就意味着要做N个列表页模板,显 ...
- [Java][Servlet] Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
Background: Servlet version 3.1(3.0之后就有了@WebServlet注解) Error 严重: Failed to destroy end point associa ...
- intellijidea课程 intellijidea神器使用技巧 3-2 livetemplate
创建livetemplate分组: ctrl shift a ==> live templates ==> + ==> templates group 创建livetemplate模 ...
- hibernate课程 初探单表映射4-1 课程总结
ORM是一种面向对象编程的方法,用这种方法来避免写数据库底层语言sql语句,这样有利于java的跨平台,扩展.维护.而hirenate是ORM的一种框架 hirbernate开发基本步骤编写配置文档h ...
- mac笔记本上的工具
svn可是换工具:cornerstone host修改工具:switchHosts!