Mybatis 报错

2022-11-03,

Mybatis 报错

builder.BuilderException: Error parsing SQL Mapper Configuration

Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/xxx/dao/UserDao.xml

这个原因是我的 resources 文件下面的 package 不能建立,因此我将其标记为 test resources,问题解决

It's likely that neither a Result Type nor a Result Map was specified

这个原因是:Mybatis配置文件中没有返回类型参数

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException 是文件查询之后不知道将结果集封装到哪里

因此在查询的方法id后面添加一个resultType,

将结果封装至User

InvalidConnectionAttributeException

还有一个关于时区的问题,此问题为时区问题,在 JDBC 的连接 url 部分加上 serverTimezone=UTC 即可。

如果选择utc会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong

UTC 即 Universal Time Coordinated 世界标准时间

Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.

解决方法:

<property name="url" value="jdbc:mysql://localhost:3306/dbMybatis?serverTimezone=UTC"/>

Mybatis 报错的相关教程结束。

《Mybatis 报错.doc》

下载本文的Word格式文档,以方便收藏与打印。