mybatis-generator

来源:互联网 发布:cloud9 ide java 编辑:程序博客网 时间:2024/04/28 19:06

generator自动生成mybatis的xml配置

标签: generator自动生成mybatis
132人阅读 评论(0)收藏举报

1、首先下载好mybatis-generator-core-1.3.2.jar包。

2、编辑generatorConfig.xml文件。详细如下:

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  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.   <!-- classPathEntry:数据库的JDBC驱动的jar包地址-->  
  8.   <classPathEntry location="mysql-connector-java-5.1.25-bin.jar" />  
  9. <context id="DB2Tables" targetRuntime="MyBatis3">  
  10.   <commentGenerator>  
  11.     <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
  12.     <property name="suppressAllComments" value="true" />  
  13.     <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->  
  14.   </commentGenerator>  
  15.   <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"  
  16.           connectionURL="jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8"  
  17.           userId="unuser"  
  18.           password="password">  
  19.   </jdbcConnection>  
  20.     <!--  默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer   
  21.          true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal   
  22.      -->   
  23.   <javaTypeResolver >  
  24.      <property name="forceBigDecimals" value="false" />  
  25.   </javaTypeResolver>  
  26.   <!-- targetProject:自动生成代码的位置 -->  
  27.   <javaModelGenerator targetPackage="com.soft.model" targetProject="E:\downAttachdemo\src">  
  28.       <!-- enableSubPackages:是否让schema作为包的后缀 -->       
  29.       <property name="enableSubPackages" value="true" />  
  30.     <!-- 从数据库返回的值被清理前后的空格  -->   
  31.       <property name="trimStrings" value="true" />  
  32.   </javaModelGenerator>  
  33.     
  34.   <sqlMapGenerator targetPackage="sqlmap"  targetProject="E:\downAttachdemo\conf">  
  35.        <property name="enableSubPackages" value="false" />  
  36.   </sqlMapGenerator>  
  37.     
  38.   <javaClientGenerator type="XMLMAPPER" targetPackage="com.soft.mapping"  targetProject="E:\downAttachdemo\src">  
  39.     <property name="enableSubPackages" value="true" />  
  40.   </javaClientGenerator>  
  41.   <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->  
  42.   <table tableName="%"  enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">  
  43.     
  44.   </table>  
  45. </context>  
  46.    
  47. </generatorConfiguration>  

able其他属性:
enableCountByExample="false" 
enableUpdateByExample="false"
enableDeleteByExample="false" 
enableSelectByExample="false"
selectByExampleQueryId="false"
schema即为数据库名, tableName为对应的数据库表, domainObjectName是要生成的实体类, 
如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true, 
这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时, 
就不会生成对应的Example类了.

3、配置好后就可以运行它了。(cmd到jar所在的目录)

[html] view plain copy 在CODE上查看代码片派生到我的代码片
java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
0 0
原创粉丝点击