Mybatis-generator使用和扩展

mybatis-generator使用

pom.xml配置

<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<dependencies>
<!-- 数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
</exclusions>
</dependency>
</dependencies>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>

generatorConfig配置

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <!-- add by luobo 2016.4.18 使用时请自行修改 -->
<generatorConfiguration>
<!-- 引入配置文件 -->
<properties resource="mybatis.generator.properties"/> <!-- 一个数据库一个context -->
<context id="mysqlTables" targetRuntime="MyBatis3"> <!-- 自定义扩展插件 -->
<plugin type="com.yt.trade.dal.util.SqlMapperGeneratorExtend" >
<property name="enableInsertSelective" value="false" />
</plugin> <!-- 注释,type是使用自定义的类生成注释,这里我主要是想把数据库的字段说明带出来 -->
<commentGenerator type="com.yt.trade.dal.util.YtCommentGenerator">
<!-- 是否取消注释 -->
<property name="suppressAllComments" value="true"/>
<!-- 是否生成注释代时间戳-->
<property name="suppressDate" value="true" />
</commentGenerator> <!-- jdbc连接 -->
<jdbcConnection driverClass="${jdbc_driver}"
connectionURL="${jdbc_url}"
userId="${jdbc_user}"
password="${jdbc_password}" /> <!-- 类型转换 -->
<javaTypeResolver>
<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver> <!-- 生成实体类地址 -->
<javaModelGenerator targetPackage="com.yt.trade.dal.order.mapper.test" targetProject="src/main/java">
<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->
<property name="enableSubPackages" value="false"/>
<!-- 是否针对string类型的字段在set的时候进行trim调用 -->
<property name="trimStrings" value="true"/>
</javaModelGenerator> <!-- 生成mapxml文件 -->
<sqlMapGenerator targetPackage="mapper.test" targetProject="src/main/resources">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator> <!-- 生成mapxml对应client,也就是接口dao -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.yt.trade.dal.order.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator> <!-- 配置表信息 -->
<!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample 是否生成 example类 -->
<table tableName="t_order_assist" domainObjectName="OrderAssist" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true"
enableInsert="true" enableCountByExample="false" enableSelectByExample="false" enableDeleteByPrimaryKey="false" enableUpdateByExample="false" enableDeleteByExample="false" >
<generatedKey column="id" sqlStatement="SELECT LAST_INSERT_ID()"/> <!-- 忽略列,不生成bean 字段 -->
<ignoreColumn column="FRED" />
<!-- 指定列的java数据类型 -->
<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> </table> <!--
<table tableName="xxxx" domainObjectName="XXXX" enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false">
<generatedKey column="id" sqlStatement="SELECT LAST_INSERT_ID()"/>
</table>
--> </context> </generatorConfiguration>

mybatis-generator扩展参考文档

Mybatis-generator使用和扩展的更多相关文章

  1. MyBatis Generator实现MySQL分页插件

    MyBatis Generator是一个非常方便的代码生成工具,它能够根据表结构生成CRUD代码,可以满足大部分需求.但是唯一让人不爽的是,生成的代码中的数据库查询没有分页功能.本文介绍如何让MyBa ...

  2. 记一次 IDEA mybatis.generator 自定义扩展插件

    在使用 idea mybatis.generator 生成的代码,遇到 生成的代码很多重复的地方, 虽然代码是生成的,我们也不应该允许重复的代码出现,因为这些代码后期都要来手动维护. 对于生成时间戳注 ...

  3. Mybatis Generator 扩展

    目标 修改Model的名称 修改Dao的名称 配置文件 context.targetRuntime 替换为自定义的类型 原理在:org.mybatis.generator.internal.Objec ...

  4. Mybatis Generator生成工具配置文件详解

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...

  5. MyBatis Generator 详解

    MyBatis Generator中文文档 MyBatis Generator中文文档地址:http://mbg.cndocs.tk/ 该中文文档由于尽可能和原文内容一致,所以有些地方如果不熟悉,看中 ...

  6. MyBatis Generator 详解 【转来纯为备忘】

    版权声明:版权归博主所有,转载请带上本文链接!联系方式:abel533@gmail.com   目录(?)[+] MyBatis Generator中文文档 运行MyBatis Generator X ...

  7. mybatis generator使用总结

    一.mybatis项目的体系结构 百度mybaits,可以进入mybatis的github:https://github.com/mybatis. mybatis是一个大大的体系,它不是孤立的,它可以 ...

  8. mybatis Generator配置文件详解

    这里按照配置的顺序对配置逐个讲解,更细的内容可以配合中文文档参照. 1. 配置文件头 <?xml version="1.0" encoding="UTF-8&quo ...

  9. mybatis generator配置文件

    <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration ...

  10. 【转】Mybatis Generator最完整配置详解

    本文转简书:http://www.jianshu.com/p/e09d2370b796 --> --> <!-- 自动识别数据库关键字,默认false,如果设置为true,根据Sql ...

随机推荐

  1. HW3.3

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  2. python —print

    今天开始学python了,“装X”安装了最新版本python 3.4.1 然后,print “hello world!" 就出错了... 一搜原来... python v3.0以后的版本pr ...

  3. PC-用Windows XP自带的组策略加固操作系统

    1.我的壁纸你别改==================================== 启动组策略时,单击“开始”按钮,选择“运行”命令,在“运行”文本框中输入“gpedit.msc”命令,即可启 ...

  4. sql server smo

    在SQL Server2005以前的版本中,SQL分布式管理对象(SQL-DMO)为我们提供了非常有效的方法来通过编程的方式管理SQL Server.SQL-DMO支持基于COM的接口,开发人员可以通 ...

  5. Android基于XMPP Smack Openfire下学习开发IM(五)连接断开重连

    学习过程中大家都碰到过连接被断开的问题给困扰吧,下面教大家如何做到连接断开后,重新连接 首先要创建连接监听器,用来监听连接状态,这里我写了一个类 继承了ConnectionListener,重写了里面 ...

  6. "用wow64exts调试64位任务管理器抓取的32位程序的dump"

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:"用wow64exts调试64位任务管理器抓取的32位程序的dump".

  7. get和post,session和cookie的一些说明

      1.GET和POST的区别 A. 从字面意思和HTTP的规范来看,GET用于获取资源信息而POST是用来更新资源信息. B. GET提交请求的数据实体会放在URL的后面,用?来分割,参数用& ...

  8. Copy-VMFile

    将文件移到或移出虚拟机可能会产生问题.首先,你需要安装集成服务,打开文件共享.这只需要一个简单的PowerShell命令:Enable-VMIntegrationService.但是你必须登录到虚拟机 ...

  9. Visual C++ 2012/2013的内存溢出检測工具

    在过去,每次编写C/C++程序的时候,VLD差点儿是我的标配.有了它,就能够放心地敲代码,随时发现内存溢出. VLD最高可支持到Visual Studio 2012.不知道以后会不会支持Visual ...

  10. MySQL批处理SQL语句

    MySQL 支持批处理的模式运行一批SQL语句,以下的样例就是实验MySQL怎样在windows下批处理运行SQL语句. create table test(id int,name varchar(2 ...