mybatis-generator的使用

第一,从官网( https://github.com/mybatis/generator/releases)上下载源码

第二,解压后lib文件夹中只有 mybatis-generator-core-1.3.2.jar、mybatis-generator-core-1.3.2-javadoc.jar、mybatis-generator-core-1.3.2-sources.jar三个jar包我们需要将mysql-connector-java-5.1.7-bin.jar或者其他数据库驱动加入其中.新建src空文件和generatorConfig.xml。文件内容如下

<?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>  

    <classPathEntry  location="mysql-connector-java-5.1.7-bin.jar"/>  
    <context id="DB2Tables"  targetRuntime="MyBatis3">  
        <commentGenerator>  
            <property name="suppressDate" value="true"/>  

            <property name="suppressAllComments" value="true"/>  
        </commentGenerator>  
       
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/zjxkmicrofinance" userId="root" password="55613">  
        </jdbcConnection>  
        <javaTypeResolver>  
            <property name="forceBigDecimals" value="false"/>  
        </javaTypeResolver>  
     
        <javaModelGenerator targetPackage="com.moon.admin.po" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
            <property name="trimStrings" value="true"/>  
        </javaModelGenerator>  

        <sqlMapGenerator targetPackage="com.moon.admin.dao.mapper" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
        </sqlMapGenerator>  

        <javaClientGenerator type="XMLMAPPER" targetPackage="com.moon.admin.dao.mapper" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
        </javaClientGenerator>  

        <table tableName="m_role" domainObjectName="Role" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="false" selectByExampleQueryId="false"></table>  
        <table tableName="m_user" domainObjectName="User" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="false" selectByExampleQueryId="true"></table>  
        <table tableName="t_user_role" domainObjectName="UserRole" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="false" selectByExampleQueryId="true"></table>
         <table tableName="m_carloan_form" domainObjectName="Carload" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="true"></table>  
          <table tableName="m_companyloan_form" domainObjectName="CompanyLoad" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table>  
           <table tableName="m_houseloan_form" domainObjectName="HoseLoad" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table>    
    </context>  
</generatorConfiguration>

注意要将数据库驱动改写成你所加入的驱动包版本号。mybatis-generator的使用_第1张图片

第三:cmd到当前目录,运行

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

注意 generatorConfig.xml 名称就是上面新建的xml文件,名称必须一样。出现MyBatis Generator finished successfully.后说明生成成功。

你可能感兴趣的:(DAO,po的逆向工程的使用)