• mybatis-generator1.3.6的使用


    下载地址:

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

    Running MyBatis Generator

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



    结果如下:



  • 相关阅读:
    微信小程序支付完整示例
    二分查找,冒泡排序, 快速排序
    JQuery放大镜效果
    js瀑布流
    linux安装字体
    使用phantomjs截图【php】
    安装supervisor
    mysql报错:BIGINT UNSIGNED value is out of range
    curl https报错: curl: (35) SSL connect error
    给www用户添加登录权限
  • 原文地址:https://www.cnblogs.com/jpfss/p/8854705.html
Copyright © 2020-2023  润新知