在使用MySQL8.x版本进行MyBatis逆向工程时,测试时发现提示column不存在,即在Mapper.xml映射文件中的SQL语句不正确,映射文件中的字段与数据库中的不一致,但是创建的pojo类正确。而且在pojo和mapper包中不仅生成了如User.java和UserMapper.java的文件,还生成了User.java.1和UserMapper.java.1文件。
最后查明问题出在MySQL版本的问题上,根据官方文档:
1 | <!--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. |
在逆向文件generatorConfig.xml中的
最终经测试可以生成正确文件,正确进行数据库操作。