下载地址:

http://blog.mybatis.org/2017/12/mybatis-generator-version-136-released.html

参考了

http://blog.csdn.net/qr719169236/article/details/51086997

在使用mybatis开发的过程中,通常我们会给数据库的每张表编写对应的domain、dao、mapping,很简单,但是工作很大,所以我们通常会使用代码生成器帮我们自动生成。具体方法如下:

mybatis-generator 下载







解压后目录结构如下:



generatorConfiguration文件配置


打开doc目录中的index.html,可以发现mybatis-generator提供了5中方法供使用(本文介绍第一种,命令行方法),分别如下:



点击From the Command Line,显示must create an XML configuration file to run MBG from the command line,就是说必须要创建一个configuration 配置文件,然后执行下面的命令:

   java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml

java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml -overwrite

java -cp mybatis-generator-core-x.x.x.jar org.mybatis.generator.api.ShellRunner -configfile generatorConfig.xml

java -cp mybatis-generator-core-x.x.x.jar org.mybatis.generator.api.ShellRunner -configfile generatorConfig.xml -overwrite


在lib目录下新建一个generatorConfig.xml文件,点击XML Configuration Reference 将里面的代码拷贝到 generatorConfig.xml 中

修改generatorConfig.xml文件。在上图中的代码中,classPathEntry为数据库连接驱动,多以将对应的jar文件放入lib文件中,location指定其路径。实例如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE generatorConfiguration
  3. PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5. <generatorConfiguration>
  6. <!--MySQL连接驱动-->
  7. <classPathEntry location="mysql-connector-java-5.1.9.jar" />
  8. <!--数据库链接URL,用户名、密码 -->
  9. <context id="MySQL" targetRuntime="MyBatis3">
  10. <commentGenerator>
  11. <property name="suppressDate" value="true"/>
  12. <!-- 是否去除自动生成的注释 true:是 : false:否 -->
  13. <property name="suppressAllComments" value="true"/>
  14. </commentGenerator>
  15. <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  16. connectionURL="jdbc:mysql://127.0.0.1/test"
  17. userId="root"
  18. password="123456">
  19. </jdbcConnection>
  20. <!--是否启用java.math.BigDecimal-->
  21. <javaTypeResolver >
  22. <property name="forceBigDecimals" value="false" />
  23. </javaTypeResolver>
  24. <javaModelGenerator targetPackage="test.model" targetProject="src">
  25. <property name="enableSubPackages" value="true" />
  26. <property name="trimStrings" value="true" />
  27. </javaModelGenerator>
  28. <sqlMapGenerator targetPackage="test.xml"  targetProject="src">
  29. <property name="enableSubPackages" value="true" />
  30. </sqlMapGenerator>
  31. <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao"  targetProject="src">
  32. <property name="enableSubPackages" value="true" />
  33. </javaClientGenerator>
  34. <table tableName="salary" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  35. </table>
  36. <table tableName="persons" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  37. </table>
  38. <table tableName="orders" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  39. </table>
  40. </context>
  41. </generatorConfiguration>
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE generatorConfiguration
  3. PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5. <generatorConfiguration>
  6. <!--MySQL连接驱动-->
  7. <classPathEntry location="mysql-connector-java-5.1.9.jar" />
  8. <!--数据库链接URL,用户名、密码 -->
  9. <context id="MySQL" targetRuntime="MyBatis3">
  10. <commentGenerator>
  11. <property name="suppressDate" value="true"/>
  12. <!-- 是否去除自动生成的注释 true:是 : false:否 -->
  13. <property name="suppressAllComments" value="true"/>
  14. </commentGenerator>
  15. <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  16. connectionURL="jdbc:mysql://127.0.0.1/test"
  17. userId="root"
  18. password="123456">
  19. </jdbcConnection>
  20. <!--是否启用java.math.BigDecimal-->
  21. <javaTypeResolver >
  22. <property name="forceBigDecimals" value="false" />
  23. </javaTypeResolver>
  24. <javaModelGenerator targetPackage="test.model" targetProject="src">
  25. <property name="enableSubPackages" value="true" />
  26. <property name="trimStrings" value="true" />
  27. </javaModelGenerator>
  28. <sqlMapGenerator targetPackage="test.xml"  targetProject="src">
  29. <property name="enableSubPackages" value="true" />
  30. </sqlMapGenerator>
  31. <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao"  targetProject="src">
  32. <property name="enableSubPackages" value="true" />
  33. </javaClientGenerator>
  34. <table tableName="salary" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  35. </table>
  36. <table tableName="persons" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  37. </table>
  38. <table tableName="orders" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  39. </table>
  40. </context>
  41. </generatorConfiguration>
<?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"> <generatorConfiguration> <!--MySQL连接驱动-->

<classPathEntry location="mysql-connector-java-5.1.9.jar" /> <!--数据库链接URL,用户名、密码 -->

<context id="MySQL" targetRuntime="MyBatis3">

<commentGenerator>

<property name="suppressDate" value="true"/>

<!-- 是否去除自动生成的注释 true:是 : false:否 -->

<property name="suppressAllComments" value="true"/>

</commentGenerator>

<jdbcConnection driverClass="com.mysql.jdbc.Driver"

connectionURL="jdbc:mysql://127.0.0.1/test"

userId="root"

password="123456">

</jdbcConnection>
&lt;!--是否启用java.math.BigDecimal--&gt;
&lt;javaTypeResolver &gt;
&lt;property name="forceBigDecimals" value="false" /&gt;
&lt;/javaTypeResolver&gt; &lt;javaModelGenerator targetPackage="test.model" targetProject="src"&gt;
&lt;property name="enableSubPackages" value="true" /&gt;
&lt;property name="trimStrings" value="true" /&gt;
&lt;/javaModelGenerator&gt; &lt;sqlMapGenerator targetPackage="test.xml" targetProject="src"&gt;
&lt;property name="enableSubPackages" value="true" /&gt;
&lt;/sqlMapGenerator&gt; &lt;javaClientGenerator type="XMLMAPPER" targetPackage="test.dao" targetProject="src"&gt;
&lt;property name="enableSubPackages" value="true" /&gt;
&lt;/javaClientGenerator&gt; &lt;table tableName="salary" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"&gt;
&lt;/table&gt;
&lt;table tableName="persons" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"&gt;
&lt;/table&gt;
&lt;table tableName="orders" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"&gt;
&lt;/table&gt;

</context>

</generatorConfiguration>

Running MyBatis Generator

执行命令前,在lib目录下先创建 配置文件中targetProject指定的文件夹。
执行命令:java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite



结果如下:

mybatis-generator1.3.6的使用的更多相关文章

  1. eclipse 4.5 离线安装mybatis generator1.3.6卡在Install New Software的解决方法

    转载:https://blog.csdn.net/ssshen14/article/details/80004459 离线插件 下载:https://github.com/mybatis/genera ...

  2. mybatis generator插件开发

    mybatis现在普遍使用的每一个人DAO框架.mybatis generator它可以基于数据库中的表结构,生成自己主动mybatis代码和配置文件,方便使用,当然,实际的使用过程中.generat ...

  3. MyBatis generator配置 overwrite 文件覆盖失效

    工具:IDEA.jdk1.8.mysql 底部有解决方法! pom.xml配置 <plugins> <!--Mybatis自动代码插入--> <plugin> &l ...

  4. MyBatis:Mybatis逆向工程问题记录

    近日我在搭建springboot+mybatis+mysql 的整合项目(自己测试玩)的时候用到了mybatis的逆向工程,来这里记录一下我的菜鸟编码过程 首先我在maven中引入这些依赖 <d ...

  5. 【分享】标准springMVC+mybatis项目maven搭建最精简教程

    文章由来:公司有个实习同学需要做毕业设计,不会搭建环境,我就代劳了,顺便分享给刚入门的小伙伴,我是自学的JAVA,所以我懂的.... (大图直接观看显示很模糊,请在图片上点击右键然后在新窗口打开看) ...

  6. Java MyBatis 插入数据库返回主键

    最近在搞一个电商系统中由于业务需求,需要在插入一条产品信息后返回产品Id,刚开始遇到一些坑,这里做下笔记,以防今后忘记. 类似下面这段代码一样获取插入后的主键 User user = new User ...

  7. [原创]mybatis中整合ehcache缓存框架的使用

    mybatis整合ehcache缓存框架的使用 mybaits的二级缓存是mapper范围级别,除了在SqlMapConfig.xml设置二级缓存的总开关,还要在具体的mapper.xml中开启二级缓 ...

  8. 【SSM框架】Spring + Springmvc + Mybatis 基本框架搭建集成教程

    本文将讲解SSM框架的基本搭建集成,并有一个简单demo案例 说明:1.本文暂未使用maven集成,jar包需要手动导入. 2.本文为基础教程,大神切勿见笑. 3.如果对您学习有帮助,欢迎各种转载,注 ...

  9. mybatis plugins实现项目【全局】读写分离

    在之前的文章中讲述过数据库主从同步和通过注解来为部分方法切换数据源实现读写分离 注解实现读写分离: http://www.cnblogs.com/xiaochangwei/p/4961807.html ...

  10. MyBatis基础入门--知识点总结

    对原生态jdbc程序的问题总结 下面是一个传统的jdbc连接oracle数据库的标准代码: public static void main(String[] args) throws Exceptio ...

随机推荐

  1. 20190719-FirstZero

    这也许也是一个成就吧? First Zero 考试 第一次 爆0 好了好了. T1 你永远不知道你在想什么. 我仿佛想出一个$\Theta(NM\log^2 N)$的$dfs$??? 蒟蒻原地爆炸 T ...

  2. poj 1654 Area(求多边形面积 && 处理误差)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16894   Accepted: 4698 Description ...

  3. Java review-basic2

    1.Implement a thread-safe (blocking) queue: Class Producer implements Runable{ Private final Blockin ...

  4. 深入浅析python中的多进程、多线程、协程

    深入浅析python中的多进程.多线程.协程 我们都知道计算机是由硬件和软件组成的.硬件中的CPU是计算机的核心,它承担计算机的所有任务. 操作系统是运行在硬件之上的软件,是计算机的管理者,它负责资源 ...

  5. jeecms9自定义标签以及使用新创建的数据库表

    转载 https://blog.csdn.net/nice_meng/article/details/89179089 本系统使用的是jeecmsv9版本,收集网上知识后,进行个人汇总 首先,自己创建 ...

  6. 机房收费系统vb.net之打包与部署(二)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/wangdan199112/article/details/28286365             ...

  7. JAVA ——int 类型除法保留两位小数

    @Test public void txfloat() { // TODO 自动生成的方法存根 int a=9; int b=7; DecimalFormat df=new DecimalFormat ...

  8. Leetcode78. Subsets子集

    给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: nums = [1,2,3] 输出: [ [3],   [1],   [2 ...

  9. Swift 之 函数与闭包的应用实例

    http://www.cocoachina.com/swift/20160106/14862.html 今天的博客算是比较基础的,还是那句话,基础这东西在什么时候都是最重要的.说到函数,只要是写过程序 ...

  10. 2019-1-17-一段能让-VisualStudio-炸掉的代码

    title author date CreateTime categories 一段能让 VisualStudio 炸掉的代码 lindexi 2019-01-17 09:55:29 +0800 20 ...