您好,登錄后才能下訂單哦!
這篇文章主要講解了“Mybatis中Mapper使用package方式配置報(bào)錯(cuò)如何解決”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Mybatis中Mapper使用package方式配置報(bào)錯(cuò)如何解決”吧!
Mybatis 中Mapper使用package方式配置報(bào)錯(cuò)
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
UserDaoTest中調(diào)用了UserDao的insert方法。
package com.mybatis.dao; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; import com.mybatis.pojo.User; @Mapper public interface UserDao { void insert( User user); int insertSelective(@Param("user") User user); int insertList(@Param("users") List<User> users); int update(@Param("user") User user); User findbyId(@Param("id")Integer id); }
已經(jīng)按照正常的package的配置方式,將接口與xml文件放在同一個(gè)目錄下,其他配置也沒問題,就是報(bào)找不到UserDao中的方法。
結(jié)果去target中看了一眼發(fā)現(xiàn),xml文件沒加載。。。。。
原來是IDEA maven項(xiàng)目默認(rèn)不會(huì)把src下除java文件外的文件打包到classes文件夾下,需要在maven中增加配置如下
<build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <!--默認(rèn)是true--> <!--<filtering>true</filtering>--> </resource> </resources> </build>
這樣xml文件就可以加載了,動(dòng)態(tài)代理為UserDao接口生成實(shí)現(xiàn)類,而實(shí)現(xiàn)類的具體實(shí)現(xiàn)細(xì)節(jié)就是在xml中,通過package掃描的方式找到xml,就可以正確的生成UserDao的代理類了。
而xml無法加載,就會(huì)造成動(dòng)態(tài)代理生成的代理類是無效的(這個(gè)代理類對(duì)象是可以生成的),當(dāng)調(diào)用方法就會(huì)出現(xiàn)開頭的錯(cuò)誤。
感謝各位的閱讀,以上就是“Mybatis中Mapper使用package方式配置報(bào)錯(cuò)如何解決”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)Mybatis中Mapper使用package方式配置報(bào)錯(cuò)如何解決這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。