Mybatis Generator [MBG] 生成指定数据库下的全部tables, 失效如何解决?

这个问题,我在stack上回答过, 我就不翻译我自己的回答了,直接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

 

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值