Mybatis generates the mapping file from the project in reverse

Time:2021-10-18

Previously, the reverse generation of mapping files through mybatis generator was in the project. This time, due to work needs, I tried to separate from the project generation

  1. Download mybatis generator utility class
  2. After decompression, enter the Lib directory, create the SRC folder and generatorconfig.xml, and put the database driver package into it. Here, take MySQL as an example
    Mybatis generates the mapping file from the project in reverse
  3. Modify the configuration file 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>
        <!-- Database driven -- >
        <classPathEntry    location="mysql-connector-java-5.0.8.jar"/>
        <context id="DB2Tables"    targetRuntime="MyBatis3">
            <commentGenerator>
                <property name="suppressDate" value="true"/>
                <property name="suppressAllComments" value="true"/>
            </commentGenerator>
            <!-- Database link address account password -- >
            <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:8989/test" userId="root" password="root">
            </jdbcConnection>
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false"/>
            </javaTypeResolver>
            <!-- Storage location of generated model class -- >
            <javaModelGenerator targetPackage="com.test.model" targetProject="src">
                <property name="enableSubPackages" value="true"/>
                <property name="trimStrings" value="true"/>
            </javaModelGenerator>
            <!-- Storage location of generated mapping file -- >
            <sqlMapGenerator targetPackage="com.test.mapping" targetProject="src">
                <property name="enableSubPackages" value="true"/>
            </sqlMapGenerator>
            <!-- Generate Dao class storage location -- >
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.test.dao" targetProject="src">
                <property name="enableSubPackages" value="true"/>
            </javaClientGenerator>
            <!-- Generate the corresponding table and class name. Tablename is the database name and domainobjectname is the mapping class name. Multiple tables can be set -- >
            <table tableName="product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        </context>
    </generatorConfiguration>
  4. Enter the tool class directory from the command line and execute the following statement
    Mybatis generates the mapping file from the project in reverse

    java -jar mybatis-generator-core-1.3.7.jar -configfile generatorConfig.xml -overwrite