今天使用mybatis-generator去生成mysql数据库中的user表,发现生成的表跟自己实际写的不一样,查询mybatis-generator官方文档
在mysql数据库信息中有这样的说明
If you are using version 8.x of Connector/J you may notice that the generator attempts to generate code for tables in the MySql information schemas (sys, information_schema, performance_schema, etc.) This is probably not what you want! To disable this behavior, add the property "nullCatalogMeansCurrent=true" to your JDBC URL.
翻译如下
如果您使用的是Connector/J的8.x版本,您可能会注意到生成器试图为MySql信息模式(sys、information_schema、performance_schema等)中的表生成代码,这可能不是您想要的!要禁用此行为,请将属性“nullCatalogMeansCurrent=true”添加到JDBC URL。
说明mysql8.x以上在生成时如果遇到表名与mysql自带的相同,则会按mysql自带的表生成代码,需要配置一个property属性到jdbcConnection标签中
即如下
<jdbcConnection
driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/my_database"
userId="my_user"
password="my_password">
<property name="nullCatalogMeansCurrent" value="true" />
</jdbcConnection>
成功解决