这个问题,我在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