mybatis反向工程配置(命令行方式)

使用步驟,step1.將兩個jar包和配置文件config.xml 放到同一個目錄下;step2.修改配置文件中的數據庫連接和表名;step3運行命令。齊活。文末有彩蛋

  1. 命令java -jar mybatis-generator-core-1.3.7.jar -configfile config.xml
  2. jar包2個
  • https://repo1.maven.org/maven2/org/mybatis/generator/mybatis-generator-core/1.3.7/mybatis-generator-core-1.3.7.jar
  • https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.46/mysql-connector-java-5.1.46.jar
  1. 配置文件,名稱爲config.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="./mysql-connector-java-5.1.46.jar"/>
    <context id="Mybatis3Context" targetRuntime="MyBatis3">
        <property name="javaFileEncoding" value="UTF-8"/>
        <!-- 1/2 修改數據庫鏈接 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/test"
                        userId="root"
                        password="123456">
        </jdbcConnection>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <javaModelGenerator targetPackage="model" targetProject="./codes">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="mapperxml" targetProject="./codes">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetPackage="mapper" targetProject="./codes">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>

        <!-- 2/2 修改表名 -->
        <table tableName="table2"  enableCountByExample="false"
               enableDeleteByExample="false" enableUpdateByExample="false" enableSelectByExample="false">
        </table>
        <table tableName="table1"  enableCountByExample="false"
               enableDeleteByExample="false" enableUpdateByExample="false" enableSelectByExample="false">
        </table>
    </context>
</generatorConfiguration>

彩蛋
去掉多餘註釋
替換xml註釋正則 <!--\n(( *\S* *)+\n){3} +-->\n
替換java註釋正則 \n */\*\*(\s+\* *(\w| |\.|@|:)*)*/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章