Exception in thread “main“ org.apache.ibatis.exceptions.PersistenceException奇葩解决方案
生活随笔
收集整理的這篇文章主要介紹了
Exception in thread “main“ org.apache.ibatis.exceptions.PersistenceException奇葩解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
項目場景:
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in com/bjsxt/mapper/UserMapper.xml問題描述:
在使用mybatis框架,通過id查詢用戶時,出現異常;
</select> <!-- 根據用戶id查詢用戶 參數類型可以不寫--><select id="selectUsersById" parameterType="int" resultType="com.bjsxt.pojo.Users">/* #{}相當于jdbc中的問號,直接在{}中給定綁定參數的名稱;如參數只有一個叫什么都可以,但要是有多個就需要具體參數名稱了;*/select * from users where userid = #{suibian}</select>原因分析:
這樣的異常:是映射文件出現了錯誤,大多數都是resultType的配置出現了錯誤,但是今天我這個錯誤優點奇葩;
解決方案:
將代碼中的注釋刪掉就解決了;
異常代碼
</select> <!-- 根據用戶id查詢用戶 參數類型可以不寫--><select id="selectUsersById" parameterType="int" resultType="com.bjsxt.pojo.Users">/* #{}相當于jdbc中的問號,直接在{}中給定綁定參數的名稱;如參數只有一個叫什么都可以,但要是有多個就需要具體參數名稱了;*/select * from users where userid = #{suibian}</select>消除異常后代碼:
</select> <!-- 根據用戶id查詢用戶 參數類型可以不寫--><select id="selectUsersById" parameterType="int" resultType="com.bjsxt.pojo.Users">select * from users where userid = #{suibian}</select>解決后我也是無語了;
在這里再加一句,不論是/* */注釋,還是選中Ctrl+/注釋都是會報相同的異常的;
在這里建議就不要加注釋了,如果真的要加還是放到select標簽外面吧!
總結
以上是生活随笔為你收集整理的Exception in thread “main“ org.apache.ibatis.exceptions.PersistenceException奇葩解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Exception in thread
- 下一篇: 多线程别怕,有锁就安全;(解决线程安全问