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
  • 相关阅读:
    Python——项目-小游戏_正式的进入开发阶段_1阶段 主程序&背景移动
    Ajax-使用教程
    JavaScript——类还有对象
    Python——项目-小游戏3-精灵?蓝精灵?
    Python——项目-小游戏2-动画绘制
    jQuery——有关于jQuery操作 属性,元素,还有尺寸位置等
    Python——项目-小游戏
    jQuery入门
    JavaScript——WEBAPIS_有关于移动端特效,还有本地存储
    性能优化之Angular前端优化总结
  • 原文地址:https://www.cnblogs.com/xiangpeng/p/7735836.html
Copyright © 2011-2022 走看看