1. 程式人生 > 實用技巧 >Mybatis 報錯

Mybatis 報錯

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"/>