今天用maven創建了一個mybatis項目,在基本的xml文件和接口都配置好之後,想在數據庫中實現增加操作,結果編譯之後,出現了這樣一個錯誤:BindingException——綁定異常,什麼意思呢?我的sql語句沒有辦法執行,查詢一番之後才明白,後來發現,使用maven創建mybatis項目時,在pom.xml文件裏面的build標籤裏,要加入這樣一段代碼:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
因爲在mapper包裏面,我們寫入了接口和xml文件,而maven默認是不會包含我們在這個包裏寫的xml文件的(默認配置爲${basedir}/src/main/resources),即directory目錄,所以要用resoursces配置將該xml文件包含進來,加上這段代碼之後,這個問題就迎刃而解。