标签归档:mybatis

mybatis自动生成代码文件

下载文件:https://code.google.com/p/mybatis/downloads/list?can=1&q=Product%3DGenerator
下载后解压,里面包含文档,我下载的是1.3.2版本。
建立generator.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:数据库的JDBC驱动的jar包地址-->  
      <classPathEntry location="D:\jarlib\jdbc\mysql-connector-java-5.1.27.jar" />  
    <context id="DB2Tables" targetRuntime="MyBatis3">  
      <commentGenerator>  
        <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
        <property name="suppressAllComments" value="true" />  
        <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->  
      </commentGenerator>  
      <jdbcConnection driverClass="com.mysql.jdbc.Driver"  
              connectionURL="jdbc:mysql://localhost:3306/mydb"  
              userId="root"  
              password="root">  
      </jdbcConnection>  
        <!--  默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer   
             true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal   
         -->   
      <javaTypeResolver >  
         <property name="forceBigDecimals" value="false" />  
      </javaTypeResolver>  
      <!-- targetProject:自动生成代码的位置 -->  
      <javaModelGenerator targetPackage="entity" targetProject="D:\workspace\jarvis\test\webtest\src">  
          <!-- enableSubPackages:是否让schema作为包的后缀 -->       
          <property name="enableSubPackages" value="true" />  
        <!-- 从数据库返回的值被清理前后的空格  -->   
          <property name="trimStrings" value="true" />  
      </javaModelGenerator>  
      <!-- mapper xml -->  
      <sqlMapGenerator targetPackage="conf"  targetProject="D:\workspace\jarvis\test\webtest\src">  
           <property name="enableSubPackages" value="false" />  
      </sqlMapGenerator>  
       <!-- mapper Interface --> 
      <javaClientGenerator type="XMLMAPPER" targetPackage="mapper"  targetProject="D:\workspace\jarvis\test\webtest\src">  
        <property name="enableSubPackages" value="true" />  
      </javaClientGenerator>  
      <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->  
      <table schema="untodo" tableName="t_student" domainObjectName="Student" >
	   <!--<property name="useActualColumnNames" value="true"/>-->
      <generatedKey column="id" sqlStatement="MySql" identity="true" />
      <columnOverride column="student_num" property="studehtNum" />
     <!-- <ignoreColumn column="FRED" /> -->
     <!-- <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />-->
	  </table>
      <table schema="untodo" tableName="t_teacher" domainObjectName="Teacher" >  </table>  
    </context>       
</generatorConfiguration>  

通过命令执行:java -jar mybatis-generator-core-1.3.1.jar -configfile D:\mybatistool\mybatis-generator-core-1.3.1\genrator.xml -overwrite