1. 程式人生 > >idea離線破解安裝 mybatis_plugin與使用

idea離線破解安裝 mybatis_plugin與使用

  1. 下載mybatis plugin包。
  2. 開啟IDEA,點選File – Settings – plugins – install plugin from disk
  3. 匯入mybatis_plus.zip,重啟idea,ok

那麼怎麼使用呢:在src/main/resources目錄下新建mybatis-generator配置檔案。

生成的程式碼如下:

<?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>

    <!-- !!!! Driver Class Path !!!! -->
    <classPathEntry location=""/>

    <context id="context" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="false"/>
            <property name="suppressDate" value="true"/>
        </commentGenerator>

        <!-- !!!! Database Configurations !!!! -->
        <jdbcConnection driverClass="" connectionURL="" userId="" password=""/>

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

        <!-- !!!! Model Configurations !!!! -->
        <javaModelGenerator targetPackage="" targetProject="THIS_CONFIGURATION_IS_NOT_REQUIRED">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!-- !!!! Mapper XML Configurations !!!! -->
        <sqlMapGenerator targetPackage="" targetProject="THIS_CONFIGURATION_IS_NOT_REQUIRED">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <!-- !!!! Mapper Interface Configurations !!!! -->
        <javaClientGenerator targetPackage="" targetProject="THIS_CONFIGURATION_IS_NOT_REQUIRED" type="XMLMAPPER">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>

        <!-- !!!! Table Configurations !!!! -->
        <table tableName="" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               enableUpdateByExample="false"/>
    </context>
</generatorConfiguration>

對以上程式碼的註釋說明:

<?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>
 
    <!--
        出現錯誤:Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        解決辦法:將本地的MAVEN倉庫中的mysql驅動引入進來
    -->
    <classPathEntry location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.6\mysql-connector-java-5.1.6.jar"/>
 
    <context id="mysqlgenerator" targetRuntime="MyBatis3">
        <!--不生成註釋-->
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!-- 配置資料庫連線 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/ssm_demo"
                        userId="root"
                        password="920614" />
 
        <!-- 指定javaBean生成的位置 -->
        <javaModelGenerator targetPackage="com.wgs.domain" targetProject="src/main/java" >
            <!-- 在targetPackage的基礎上,根據資料庫的schema再生成一層package,最終生成的類放在這個package下,預設為false -->
            <property name="enableSubPackages" value="true" />
            <!-- 設定是否在getter方法中,對String型別欄位呼叫trim()方法 -->
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
 
        <!--指定sql對映檔案生成的位置 -->
        <sqlMapGenerator targetPackage="com.wgs.dao" targetProject="src/main/resources" >
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
        <!-- 指定dao介面生成的位置,mapper介面 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.wgs.dao" targetProject="src/main/java" >
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
 
        <!-- table表生成對應的DoaminObject -->
        <table tableName="tbl_emp" domainObjectName="Employee"></table>
        <table tableName="tbl_dept" domainObjectName="Department"></table>
 
    </context>
 
</generatorConfiguration>