zoukankan      html  css  js  c++  java
  • mybatis自动生成mapper,dao映射文件

    利用Mybatis-Generator来帮我们自动生成mapper.xml文件,dao文件,model文件。

    1、所需文件

    关于Mybatis-Generator的下载可以到这个地址:https://github.com/mybatis/generator/releases

    以下是相关文件截图:

    从以上截图中可以看出来有一个generator.xml文件,主要就是修改这个文件中的配置信息。

    mybaits-generator-core-1032.jar为mybaits生成器的核心包。

    mysql-connector-java-5.1.34.jar为连接mysql的jar包;ojdbc6.jar为连接oracle的jar包,根据需要选择不同的jar包。

    generatorConfig.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 location="E:webjava_mybitsgeneratorojdbc6.jar" /> <!-- 本次我的数据库为oracle,所以选择此jar包 -->
      <!-- <classPathEntry location="C:oracleproduct10.2.0db_1jdbclibojdbc14.jar" />--> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 数据库链接URL、用户名、密码 --> <!--<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhots:3306/my_db?characterEncoding=utf8" userId="root" password="123456">--> <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@11.10.97.14:1521:TESTOMS" userId="kfomswas" password="kfomswas"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="dh.model" targetProject="E:webjava_mybitsgeneratorsrc"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成的映射文件包名和位置 --> <sqlMapGenerator targetPackage="dh.mapping" targetProject="E:webjava_mybitsgeneratorsrc"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="dh.dao" targetProject="E:webjava_mybitsgeneratorsrc"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- 要生成那些表(更改tableName和domainObjectName就可以) --> <table tableName="DH_DESIGN_TASK" domainObjectName="DhDesignTask" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    <!--
              <table tableName="course_info" domainObjectName="CourseInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> <table tableName="course_user_info" domainObjectName="CourseUserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    --> </context> </generatorConfiguration>

     如上代码所示:

    修改下划线部分就能够生成相应的文件。多表一次性生成文件只需在上面的红色标注部分的注释释放掉,并修改相应的表名即可。

    2、生成语句

    java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite

    3、生成步骤

    在该目录下的路径框内输入cmd,并按Enter,输入生成语句

    再回车之后显示:MyBatis Generator finished successfully

    在该目录下就生成了相应的文件

     相应的文件已上传至文件库。

    yian
  • 相关阅读:
    Visual Studio 出现生成错误 ,要继续并运行上次的成功生成吗?
    postgresql迁mysql之后兼容性问题
    Java中把十进制转为二进制(判断有效的ip地址和掩码)
    Java中如何把整数变为二进制输出
    Java二进制与十进制转换及位运算
    面试知识点总结之开放性问题
    面试知识点总结之常用设计模式
    linux下VIRT,RES,SHR的含义
    JSP JS 日期控件的下载、使用及注意事项
    Html5实现头像上传和编辑,保存为Base64的图片过程
  • 原文地址:https://www.cnblogs.com/xiangpeng/p/7735836.html
Copyright © 2011-2022 走看看