1. 程式人生 > >IDEA中spring boot MyBatis出現Invalid bound statement (not found)錯誤

IDEA中spring boot MyBatis出現Invalid bound statement (not found)錯誤

同樣的專案在eclipse中沒有問題在idea中mybatis會報Invalid bound statement (not found)錯誤

原因是沒有找到相對應的XML檔案,找了很長時間發現在編譯後的classes路徑下並沒有相應的XML檔案,這是因為IDEA在編譯的時候忽略掉了XML檔案,一個解決方法是將所有的XML檔案移動到Resource資料夾下,這樣在編譯的時候就會將XML檔案一起編譯

可以在resource目錄下建立一個mapper資料夾,然後將*mapper.xml檔案放裡面 ,如果去檔案系統裡看過專案目錄的話就會發現resource其實就是專案的根目錄

然後更改application.yml檔案  :

mapper-locations: classpath*:mapper/*Mapper.xml