Mybatis Generator [MBG] 生成指定數據庫下的全部tables, 失效如何解決?

這是我之前的回答,我就不翻譯了,直接copy過來.

歸根結底就原因是:

MySql不能正確支持SQL目錄和架構。如果 在MySql中運行create schema命令,它實際上會創建一個數據庫 - 並且JDBC驅動程序將其作爲目錄報告回來。但是MySql語法不支持標準的catalog..table SQL語法。因此,最好不要在生成器配置中指定目錄或模式。只需指定表名並在JDBC URL中指定數據庫即可

      <jdbcConnection
            driverClass="${driverClassName}"
            connectionURL="${url}"
            userId="${username}"
            password="${password}">
        <property name="nullCatalogMeansCurrent" value="true" />
      </jdbcConnection>

If you use MySQL, The crucial point is this:
{property name="nullCatalogMeansCurrent" value="true"}

 

我之前的原文回答是這樣的,原諒我直接拷貝過來了:

You should rewrite your generatorConfig.xml like this:

<table tableName="yourTableName" domainObjectName="JavaBeanName"
   enableCountByExample="false" 
   enableUpdateByExample="false"
   enableDeleteByExample="false" 
   enableSelectByExample="false"
   selectByExampleQueryId="false" 
   enableDeleteByPrimaryKey="false"
   enableInsert="false" 
   enableUpdateByPrimaryKey="false">
</table>

If you use MySQL, The crucial point is this:
{property name="nullCatalogMeansCurrent" value="true"}
reference: http://www.mybatis.org/generator/usage/intro.html

       <jdbcConnection
            driverClass="${driverClassName}"
            connectionURL="${url}"
            userId="${username}"
            password="${password}">
        <property name="nullCatalogMeansCurrent" value="true" />
    </jdbcConnection>

For eg:

<generatorConfiguration>
<properties resource="mybatis-generator/generator.properties"></properties>
<classPathEntry location="${driverLocation}"/>
<context id="default" targetRuntime="MyBatis3">
    <commentGenerator>
        <property name="suppressDate" value="true"/>
        <property name="suppressAllComments" value="true"/>
    </commentGenerator>

    <jdbcConnection
            driverClass="${driverClassName}"
            connectionURL="${url}"
            userId="${username}"
            password="${password}">
       **<property name="nullCatalogMeansCurrent" value="true" />**
    </jdbcConnection>

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

    <javaModelGenerator targetPackage="com.entity" targetProject="src/main/java">

        <property name="enableSubPackages" value="true"/>
    </javaModelGenerator>


    <sqlMapGenerator targetPackage="com.daoMappers" targetProject="src/main/resources">
        <property name="enableSubPackages" value="true"/>
    </sqlMapGenerator>


    <javaClientGenerator targetPackage="com.dao" targetProject="src/main/java" type="XMLMAPPER">
        <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>


    <table tableName="student" domainObjectName="Student"
           enableCountByExample="false" 
           enableUpdateByExample="false"
           enableDeleteByExample="false" 
           enableSelectByExample="false"
           selectByExampleQueryId="false" 
           enableDeleteByPrimaryKey="false"
           enableInsert="false" 
           enableUpdateByPrimaryKey="false">
    </table>
</context>

Notes those should setting by yourself

<properties resource="mybatis-generator/generator.properties"></properties>
<classPathEntry location="${driverLocation}"/>

The file of generator.properties coding like this:

driverClassName=com.mysql.cj.jdbc.Driver

driverLocation=/Users/mac/.m2/repository/mysql/mysql-connector-java/6.0.6/mysql-connector-java-6.0.6.jar

url=jdbc:mysql://localhost:3306/student?useSSL=false&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true
username=xxx
password=xxx

 

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