mybatis自动生成代码generator

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LONG729564606/article/details/77878437

mybatis-generator-core-1.3.2.jar包
编写genertor的xml文件,名下: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>  
  <!-- 数据库的JDBC驱动的jar包地址-->  
  <classPathEntry location="D:\mysql-connector-java-5.1.13-bin.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/test" userId="root" password="root" /> 
    <!--  默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer   
         true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal   
     -->   
  <javaTypeResolver >  
     <property name="forceBigDecimals" value="false" />  
  </javaTypeResolver>  
  <!-- 自动生成代码的包名和位置,targetProject可以写绝对路径也可以写项目名 -->  
  <javaModelGenerator targetPackage="com.test.model" targetProject="E:\eclipse\workspace\ssm\src">  
      <!-- 是否让schema作为包的后缀 -->       
      <property name="enableSubPackages" value="true" />  
       <!-- 生成的映射文件报名和位置 -->  
        <sqlMapGenerator targetPackage="com.test.mapper" targetProject="ssm" />  
        <!-- 生成DAO的包名和位置 -->  
        <javaClientGenerator targetPackage="com.test.mapper" targetProject="ssm" type="XMLMAPPER" /> 
    <!-- 从数据库返回的值被清理前后的空格  -->   
      <property name="trimStrings" value="true" />  
  </javaModelGenerator>  

         <!-- domainObjectName是表对应的实体类名,  tableName是对应的表名-->  
        <!-- table可以配置多个,enable*几个参数是为了自动生成一些额外的sql操作,可以关闭-->  
        <!-- 
schema即为数据库名, tableName为对应的数据库表, domainObjectName是要生成的实体类, 
如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true, 
这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时, 
就不会生成对应的Example类了. 
如果table里边不配置property,默认字段都生成为类属性。 
<ignoreColumn column="FRED" />//忽略字段 
<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />//无论字段是什么类型,生成的类属性都是varchar。   -->
  <table schema="test" tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false"  
            enableDeleteByExample="false" enableSelectByExample="false"    selectByExampleQueryId="false">  

  </table>  
</context>  
</generatorConfiguration>  

猜你喜欢

转载自blog.csdn.net/LONG729564606/article/details/77878437