Invalid bound statement (not found)
阿新 • • 發佈:2021-07-28
今天在寫springboot時候基本的查詢功能,啟動專案之後出現了了這個bug,
翻譯一下是無效的繫結語句(未找到),然後去檢視是否是配置檔案的事情.
檢查之後發現沒有,然後我嘗試了下面的方法,問題解決.
**1.你的mapper寫在了java目錄裡面。例如下圖:這樣會出現一個問題,即使你在properties裡面配置了 mybatis.mapper-locations= classpath:com/lihaoyu/demo/dao/.xml,也沒有用,因為編譯的時候這個xml檔案並沒有被自動拉到target裡面,畢竟編譯的是.java檔案而不是xml嘛,所以這時候應該在pom檔案裡面加上:
'''
</build> <resources> <resource> <directory>src/main/java</directory><!--所在的目錄--> <includes><!--包括目錄下的.properties,.xml檔案都會掃描到--> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build>
看了一下我的配置檔案,spring官方提供的應該沒有問題
如果你把xml放到了resources檔案下,那麼就只需要配置mybatis.mapper-locations=classpath:/mapper/.xml 就可以了,因為構建的時候會把resources裡的東西自動拉到classpath下,注意.classpath意思就是編譯後target資料夾下的classes目錄.
我的錯誤是第二種 xml裡面的namespace不對 或者id和mapper裡面的方法名不一樣,或者parameterType對應不上,都會出現這種問題。
'''
<sql id="table">administrator</sql> <select id="selectAll" resultType="com.entity.Admin"> select * from <include refid="table"/> </select>
'''
sql 後的id配置寫錯了 導致mybatis 找不到. 配置檔案放在了src下面
更改為 resource下的mapper.xml
bug 解決