在尝试解决问题的时候,也找了很多的博客,很多说法是数据库表的字段类型使用了text,因为在不查询大字段时,用Example就足够了,update同理,而检索大字段时,必须使用WithBLOBs。还有则说是字段中用了二进制。
可是上述情况都不是我的碰见的,但还是生成了***WithBLOBs.java文件。以下就我的问题和解决方法:
[WARNING] Some problems were encountered while building the effective model for com:demo:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: mysql:mysql-connector-java:jar -> version (?) vs 8.0.11 @ line 84, column 15
[WARNING] 'dependencies.dependency.scope' for org.springframework.boot:spring-boot-devtools:jar must be one of [provided, compile, runtime, test, system] but is 'true'. @ line 94, column 11
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
……
[INFO] Introspecting table user
[INFO] Generating Example class for table user
[INFO] Generating Primary Key class for table user
[INFO] Generating Record class for table user
[INFO] Generating Record class (with BLOBs) for table user
[INFO] Generating Mapper Interface for table user
[INFO] Generating SQL Map for table user
[INFO] Generating Example class for table user
[INFO] Generating Record class for table user
[INFO] Generating Mapper Interface for table user
[INFO] Generating SQL Map for table user
[INFO] Saving file UserMapper.xml
[INFO] Saving file UserMapper.xml
[INFO] Saving file UserExample.java
[INFO] Saving file UserKey.java
[INFO] Saving file User.java
[INFO] Saving file UserWithBLOBs.java
[INFO] Saving file UserMapper.java
[INFO] Saving file UserExample.java
[INFO] Saving file User.java
[INFO] Saving file UserMapper.java
[WARNING] Table Configuration user matched more than one table (mysql..user,houserent..user)
[WARNING] Column id, specified as an identity column in table user, does not exist in the table.
原因
?使用了version 8.x 的 Connector/J
因为我的 Mysql 版本是8.0,所以使用的Connector也是8.0,很多博客说要把Connector用回低版本,这样就不会出现问题,但是官方文档是建议使用8.x
在[MyBatis Generator] 的官方英文文档中有提到这个问题:→MyBatis Generator
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.
For example:
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/my_schema"
userId="my_user" password="my_password">
<property name="nullCatalogMeansCurrent" value="true" />
</jdbcConnection>
翻译过来就是:
如果您使用的是Connector / J的8.x版,您可能会注意到生成器尝试为MySql信息模式(sys,information_schema,performance_schema等)中的表生成代码。这可能不是您想要的! 要禁用此行为,请将属性“nullCatalogMeansCurrent = true”添加到JDBC URL。
将该属性加入进config.xml文件中,重新生成代码,可以看见之前的 UserWithBLOBs.java 和 UserKey.java 文件不再生成了。
以下是几个警告的解决:
1.重复引用了依赖包,在pom文件中删除多余的依赖
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: mysql:mysql-connector-java:jar -> version (?) vs 8.0.11 @ line 84, column 15
2.依赖包中的参数问题
[WARNING] 'dependencies.dependency.scope' for org.springframework.boot:spring-boot-devtools:jar must be one of [provided, compile, runtime, test, system] but is 'true'. @ line 89, column 11
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>test</scope> <!--此处的设置-->
</dependency>