一次mapper.xml配置文件問題

一、包結構

mapper所在的包結構:
在這裏插入圖片描述

二、問題描述

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) : 
com.dapeng.flow.repository.mapper.RoleUserMapper.listUserId

經檢查,RoleUserMapper.java中listUserId與RoleUserMapper.xml的對應id一致,xml所在namespace也沒錯,xml返回類型也沒有錯。經過一邊耗時的排查,發現是mapper.xml所在位置在非resource下造成的。

三、解決方案

在項目所在的pom.xml中配置mapper所在的包掃描:

<resources>
    <!--mapper.xml如果沒有放置在resource下,需要進行如下配置,否則會出現如下問題:
    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
    -->
    <resource>
		<directory>src/main/java</directory>
		<includes>
			<include>**/*.xml</include>
		</includes>
    </resource>
</resources>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章