天天看點

【Mybatis報錯】Invalid bound statement (not found)

今天啟動項目的時候,spring boot報錯了。

這個報錯,是因為mapper檔案沒有被掃描到。

為什麼沒有掃描到呢?

原因分析

  1. namespace不正确
  2. 方法未定義 :Mapper.xml中的方法沒有在java類中定義
  3. 傳回值有誤 :java類中的方法傳回值,和xml檔案中的傳回值不同(ResultMap或者ResultType)
  4. 配置路徑有誤 :mapper檔案的配置路徑是否正确
    【Mybatis報錯】Invalid bound statement (not found)
    【Mybatis報錯】Invalid bound statement (not found)
    【Mybatis報錯】Invalid bound statement (not found)

我的項目的報錯原因是第4個:mapper檔案的配置路徑不正确

我在項目裡配置的路徑是:mapper檔案夾下,及其子檔案夾下的 所有xml檔案。

但是,我的項目根本沒有mapper檔案夾。

【Mybatis報錯】Invalid bound statement (not found)

光看這個檔案夾,我并不知道它是一級目錄,還是分級目錄。

我當時建立檔案夾的時候,是一口氣輸入的

雖然檔案夾的名字寫對了,但是這個檔案夾的名字卻是 mapper.subnet

【Mybatis報錯】Invalid bound statement (not found)

在這樣的情況,根本沒有mapper檔案夾,自然也就無法比對了。