zoukankan      html  css  js  c++  java
  • Ibatis自动生成dao sqlmapper文件和domain文件过程

    generator自动生成mybatis的xml配置、model、map等信息: 
    1、下载mybatis-generator-core-1.3.2.jar包。 
           网址:http://code.google.com/p/mybatis/downloads/list?can=3&q=Product%3DGenerator,下载mybatis-generator-core-1.3.2-bundle.zip,解压 
           找到lib下的需要jar包。 
    2、新建工程项目
     
    3、编写genertor的xml文件,名下:generator.xml
     
    1. <?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 location="D:apache-tomcat-7.0.52webapps raceSysWEB-INFlibmysql-connector-java-5.1.29.jar" />
    5. <context id="context1">
    6. <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/trace_sys" userId="root" password="" />
    7. <javaModelGenerator targetPackage="com.trace.domain"
    8. targetProject="D:cpn-work raceSyssrcmainjava" />
    9. <sqlMapGenerator targetPackage="com.trace.dao" targetProject="D:cpn-work raceSyssrcmainjava"></sqlMapGenerator>
    10. <javaClientGenerator targetPackage="com.trace.dao"
    11. targetProject="D:cpn-work raceSyssrcmainjava" type="XMLMAPPER" />
    12. <table tableName="company" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    13. <table tableName="goods" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    14. <table tableName="goods_discuss" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    15. <table tableName="goods_production" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    16. <table tableName="goods_profile" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    17. <table tableName="goods_record" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    18. <table tableName="type" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    19. <table tableName="user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    20. </context>
    21. </generatorConfiguration>
    table其他属性: 
    enableCountByExample="false" 
    enableUpdateByExample="false" 
    enableDeleteByExample="false" 
    enableSelectByExample="false" 
    selectByExampleQueryId="false" 
    schema即为数据库名, tableName为对应的数据库表, domainObjectName是要生成的实体类, 
    如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true, 
    这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时, 
    就不会生成对应的Example类了. 



     
    4、命令行方式生成
    1. java -jar E:Websoftmybaitsmybatis-generator-core-1.3.2libmybatis-generator-core-1.3.2.jar -configfile E:WebWorkSpaceworkspace_jsdownAttachdemosrccommochasoftdowngenerator.xml -overwrite
    成功时输出:MyBatis Generator finished successfully. 




     




  • 相关阅读:
    关于WP7的Loaded事件[转]
    皮皮书屋的变态验证码
    近期学习内容for mobile
    一个js问题引发的同时吐槽
    powerdesigner 概念模型转物理模型时的丢表问题
    偶的处女文近期学习计划
    web布局实现圆角,兼容所有的浏览器
    最近面试asp.net碰到的一些题
    网站推广心得
    兼容ie6的png格式图片的背景透明问题
  • 原文地址:https://www.cnblogs.com/wang3680/p/21ea231bbba9e7bbf65a45206d7042e3.html
Copyright © 2011-2022 走看看