Mybatis generates the mapping file from the project in reverse


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 Generator Configuration 1.0//EN"
        <!-- Database driven -- >
        <classPathEntry    location="mysql-connector-java-5.0.8.jar"/>
        <context id="DB2Tables"    targetRuntime="MyBatis3">
                <property name="suppressDate" value="true"/>
                <property name="suppressAllComments" value="true"/>
            <!-- Database link address account password -- >
            <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:8989/test" userId="root" password="root">
                <property name="forceBigDecimals" value="false"/>
            <!-- Storage location of generated model class -- >
            <javaModelGenerator targetPackage="com.test.model" targetProject="src">
                <property name="enableSubPackages" value="true"/>
                <property name="trimStrings" value="true"/>
            <!-- Storage location of generated mapping file -- >
            <sqlMapGenerator targetPackage="com.test.mapping" targetProject="src">
                <property name="enableSubPackages" value="true"/>
            <!-- Generate Dao class storage location -- >
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.test.dao" targetProject="src">
                <property name="enableSubPackages" value="true"/>
            <!-- 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>
  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