• mybatis generator 源码学习


    mybatis/generator 源码地址
    mybatis/parent 源码地址
    1. 分别点击Download ZIP下载到本地。

    2. 解压generator-master.zip中的core到generator-master目录,然后解压parent-master.zip中的pom.xml到generator-master目录下

    3. 进入core目录,修改该目录下的pom.xml文件,将<relativePath />改成:<relativePath>../pom.xml</relativePath>

    <parent>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-parent</artifactId>
    <version>31-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
    </parent>
    1
    2
    3
    4
    5
    6
    4. 删除红箭头指向的三个文件和文件夹,然后在此目录下打开cmd执行命令:

    mvn -N io.takari:maven:wrapper
    1
    会重新生成。

    5. 执行命令:

    mvnw clean install -DskipTests
    1
    就会在本地仓库生成:

    6. 测试:将mybatis-generator-core-1.4.0-SNAPSHOT.jar 和 generatorConfig.xml 拷贝到一个目录中。在目录中执行如下命令:

    java -jar mybatis-generator-core-1.4.0-SNAPSHOT.jar -configfile generatorConfig.xml -overwrite
    1
    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="D:****mysqlmysql-connector-java5.1.47mysql-connector-java-5.1.47.jar" />
    <context id="DB2Tables" targetRuntime="MyBatis3">
    <commentGenerator>
    <property name="suppressAllComments" value="true" />
    </commentGenerator>
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
    connectionURL="jdbc:mysql://localhost:3306/test?useSSL=false"
    userId="root" password="123456">
    </jdbcConnection>
    <javaTypeResolver>
    <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>
    <!--域模型层,生成的目标包,项目目标源文件 -->
    <javaModelGenerator targetPackage="com.pyg.pojo"
    targetProject="./">
    <property name="enableSubPackages" value="true" />
    <property name="trimStrings" value="true" />
    </javaModelGenerator>
    <!--XML映射文件,生成的位置(目标包),源代码文件夹 -->
    <sqlMapGenerator targetPackage="com.pyg.mapper"
    targetProject="./">
    <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>
    <!--XML对应的Mapper类 -->
    <javaClientGenerator type="XMLMAPPER"
    targetPackage="com.pyg.mapper" targetProject="./">
    <property name="enableSubPackages" value="true" />
    </javaClientGenerator>
    <!-- 表名tb_item_cat,如果想要生成对应的类名为ItemCat,需要加domainObjectRenamingRule -->
    <table schema="" tableName="tb_item_cat"
    enableCountByExample="false" enableSelectByExample="false"
    enableUpdateByExample="false" enableDeleteByExample="false">
    <domainObjectRenamingRule searchString="^Tb" replaceString=""/>
    </table>
    <!-- 多表一起生成 -->
    <!-- <table schema="" tableName="%"
    enableCountByExample="false" enableSelectByExample="false"
    enableUpdateByExample="false" enableDeleteByExample="false">
    <domainObjectRenamingRule searchString="^Tb" replaceString=""/>
    </table> -->
    </context>

    </generatorConfiguration>
    ---------------------
    作者:dono118
    来源:CSDN
    原文:https://blog.csdn.net/dono118/article/details/82980841
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    CCF计算机职业资格认证考试 201809-2 买菜
    【CodeVS3013】单词背诵
    【CodeVS3304】水果姐逛水果街Ⅰ
    【CodeVS4246】奶牛的身高
    【hdu1247】Hat’s Words
    【CodeVS4189】字典
    【CodeVS4244】平衡树练习
    【poj3264】Balanced Lineup
    【树状数组】
    【CodeVS1163】访问艺术馆
  • 原文地址:https://www.cnblogs.com/lykbk/p/qwreqweqweqeweq32453434343.html
Copyright © 2020-2023  润新知