今天在學習mybatis操作數據庫的時候,出現了以下異常:
org.apache.ibatis.exceptions.PersistenceException:
Error building SqlSession.
The error may exist in com/yx/model/sqlmap/User.xml
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is ‘com/yx/model/sqlmap/User.xml’. Cause: org.apache.ibatis.builder.BuilderException: Mapper’s namespace cannot be empty
代碼報錯位置
仔細檢查了代碼發現並沒有錯誤,於是檢查配置文件。
此時,我注意到了錯誤中的一行提示
可以看到,此處明確指出namespace不能爲空。可是,什麼是namespace?
於是我打開了mybatis自帶的使用嚮導:
發現在他的mapper標籤中確實有一個屬性namespace
於是我查閱了一下這裏應該填入什麼。
原來,namespace是用於綁定Dao接口的。那麼在這裏只需要寫入你操作的接口名稱即可。