zoukankan      html  css  js  c++  java
  • 命令+mybatis-generator插件自己主动生成Mapper映射文件

    学mybatis的时候,自己写各种 *Mapper.xml和 *Mapper.java,注意各种sql语句中的 id 是否匹配。xml中的namespace是否正确,非常麻烦有木有?今天博客内容就是高大上的自己主动构建~

    1. 须要的工具包、文件
      jar包自己上网找资源就好了
    2. 以下来介绍一下generator.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="D:softwarelibmysql-connector-java-5.1.21.jar" /> -->
        <classPathEntry location="E:mysql-connector-java-5.1.29-bin.jar" />
        <context id="DB2Tables" targetRuntime="MyBatis3">
            <commentGenerator>
                <property name="suppressAllComments" value="true" />
            </commentGenerator>
            <!-- 数据库链接URL、username、密码  jdbc:mysql://localhost:3306/cinema-->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/cinema" userId="root" password="a">
            <!-- <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa"> -->
            </jdbcConnection>
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
            <!-- 生成模型的包名和位置 -->
            <javaModelGenerator targetPackage="com.rindy.cinema.entity" targetProject="E:src">
                <property name="enableSubPackages" value="true" />
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
            <!-- 生成的映射文件包名和位置 -->
            <sqlMapGenerator targetPackage="mapper" targetProject="E:src">
                <property name="enableSubPackages" value="true" />
            </sqlMapGenerator>
            <!-- 生成DAO的包名和位置 -->
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.rindy.cinema.mapper" targetProject="E:src">
                <property name="enableSubPackages" value="true" />
            </javaClientGenerator>
            <!-- 要生成那些表(更改tableName和domainObjectName就能够)这里是生成两张表的映射文件。多表可自行添加。确保你的数据库中已经建好表,而且表名没有写错~ -->
            <table tableName="filminfo" domainObjectName="FILMINFO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
            <table tableName="filmtype" domainObjectName="FILMTYPE" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    
        </context>
    </generatorConfiguration>

    3.上图中的 src是为生成的映射文件新建的空文件夹。构建成功。该文件夹下将会有你须要的文件。

    4.自己主动生成Mapper映射文件命令:

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

    5.以下来看一下我的执行结果:
    这里写图片描写叙述

    6.可能有的小伙伴会由于编码格式而引发一些错误,我们来看一下以下这样的情况怎么解决
    这里写图片描写叙述
    改一下编码格式就能够了
    这里写图片描写叙述
    ok

  • 相关阅读:
    iOS遍历程序内某个文件夹下所有文件的属性
    CATransition 转场动画
    Xcode安装的推送证书所在目录
    UIMenuController 实现长按显示自定义菜单功能
    ios调用第三方程序打开文件,以及第三方调用自己的APP打开文件
    购物车界面,不同section,点击增减物品,确定取消选中的逻辑判断
    iOS UINavigationController
    iOS9 URL Schme 白名单
    iOS9 HTTPS
    iOS9 后台定位
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/7223584.html
Copyright © 2011-2022 走看看