MyBatis Generator生成sqlMap、DAO、mo

来源:互联网 发布:开源 数据上报 编辑:程序博客网 时间:2024/06/16 21:45
  1. 附件下载地址:http://pan.baidu.com/s/1bpgEZwz  
  2. 附件中mybatis-generator-core-1.3.2.jar  、 mysql-connector-5.1.25-bin.jar  、 a.bat  、 generatorConfig.xml。  
  3. 其中mybatis-generator-core-1.3.2.jar是生成sqlMap等需要用到的jar, mysql-connector-5.1.25-bin.jar为连接sql用到的sqlMap . ;a.bat是处理命令 。   
  4. generatorConfig.xml为生成sqlmap的配置文件。  
  5.   
  6.   
  7. a.bat 、generatorConfig.xml 需要根据修改。  
  8. 1、右键a.bat,编辑,根据自己的实际路径修改a.bat中jar包路径和配置文件路径。  
  9. 2、generatorConfig.xml 修改:  

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. <pre name="code" class="html"><?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >  
  3. <generatorConfiguration>  
  4.     <classPathEntry  
  5.         location="C:/Users/Administrator/Downloads/myibatis_10586/mysql-connector-5.1.25-bin.jar" />  
  6.     <context id="context1">  
  7.         <commentGenerator>  
  8.             <property name="suppressDate" value="true" />  
  9.         </commentGenerator>  
  10.         <jdbcConnection driverClass="com.mysql.jdbc.Driver"  
  11.             connectionURL="jdbc:mysql://localhost:3306/test_web"  
  12.             userId="root" password="root">  
  13.         </jdbcConnection>  
  14.         <javaTypeResolver>  
  15.             <property name="forceBigDecimals" value="false" />  
  16.         </javaTypeResolver>  
  17.          <!--生成Model类存放位置-->  
  18.         <javaModelGenerator targetPackage="com.sql.sqlmap.model"  
  19.             targetProject="D:\Workspaces_yy_v_1_4_1\TestDB2sqlmap\src" />  
  20.         <!--生成映射文件存放位置-->  
  21.         <sqlMapGenerator targetPackage="com.sql.sqlmap.mapper"  
  22.             targetProject="D:\Workspaces_yy_v_1_4_1\TestDB2sqlmap\src" />  
  23.         <!--生成Dao类存放位置-->  
  24.         <javaClientGenerator targetPackage="com.sql.sqlmap.mapper"  
  25.             targetProject="D:\Workspaces_yy_v_1_4_1\TestDB2sqlmap\src" type="XMLMAPPER">  
  26.             <property name="enableSubPackages" value="true" />  
  27.         </javaClientGenerator>  
  28.       
  29.          <!--生成对应表及类名-->  
  30.         <!-- 其中tableName是必填的,domainObjectName默认是tableName首字母大写。  
  31.          enableCountByExample、enableUpdateByExample、enableDeleteByExample 、enableSelectByExample、selectByExampleQueryId  
  32.          默认为true,生成对应sqlMap中的方法-->  
  33.          <table tableName="user" domainObjectName="User" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table>  
  34.         <table tableName="message" domainObjectName="Messgae" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table>  
  35.         <table tableName="info" domainObjectName="Info" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table>  
  36. </context>  
  37. </generatorConfiguration>  


[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. connectionURL:改为相应的数据库连接地址。  
  2. userId :数据库用户名  
  3. password :数据库连接密码  
  4. javaModelGenerator 、sqlMapGenerator  、 javaClientGenerator 标签 需要根据实际的包名以及路径来修改。  
  5. table 标签 填写的是需要生成DAO、model、sqlMap的表。tableName必填,其他可选。domainObjectName默认是表名首字母大写。  
  6. enableCountByExample、enableUpdateByExample 、enableDeleteByExample、enableSelectByExample、selectByExampleQueryId默认  
  7. 为true。  
  8.   
  9.   
  10. 3、配置好a.bat以及eneratorConfig.xml 后,双击a.bat运行。  
  11. 4、运行成功后可以在targetPackage(此处为com.sql.sqlmap.model和com.sql.sqlmap.mapper)处看到model、dao、sqlMap。
0 0
原创粉丝点击