在maven中集成了MBG以后,生成xml等映射文件时,会生成多次。由于xml文件是追加,导致xml文件有多次生成的结果。
原因:
1):在数据库服务器上,不同的数据库中表名相同的表多张。(有几个同名的表,就会生成几次)
2):mysql驱动升级到8.x,造成设置schema无效。
解决方法:
jdbc连接新增nullCatalogMeansCurrent属性:
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf-8"
userId="root" password="root">
<property name="nullCatalogMeansCurrent" value="true" />
</jdbcConnection>
官方解释:
http://www.mybatis.org/generator/usage/mysql.html
Catalogs and Schema
MySql does not properly support SQL catalogs and schema. If you run the create schema command in MySql, it actually creates a database - and the JDBC driver reports it back as a catalog. But MySql syntax does not support the standard catalog..table SQL syntax.
For this reason, it is best to not specify either catalog or schema in generator configurations. Just specify table names and specify the database in the JDBC URL.
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.
在Maven中集成MBG后,因同名表及MySQL驱动升级至8.x,导致XML映射文件重复生成问题。解决方法是在JDBC连接中新增nullCatalogMeansCurrent属性。
498

被折叠的 条评论
为什么被折叠?



