Invalid bound statement (not found)
说明
可能每个人遇到这个情况不同,此方法不一定能解决您的问题。
背景
使用spring + mybatis + gauge来写bdd用例,表user_info用mybatis generator自动生成的mapper.xml, mapper.java, model。
自动生成的查询无法满足结果,然后自己加了一个查询方法。
贴一下xml
这里是自动生成的
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from user_info
where user_no = #{userNo,jdbcType=BIGINT}
</select>
这里是我自己添加的,和上面除了字段名,id不同外,其他完全一样
<select id="selectByCustomerId" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List"/>
from user_info
where customer_id = #{customerId,jdbcType=BIGINT}
</select>
帖一下mapper.java
这里系统生成
UserInfo selectByPrimaryKey(Long userNo);
我自己加的
List<UserInfo> selectByCustomerId(@Param("customerId") Long customerId);
然而事情没有那么简单, 系统生成的方法可以正常调用,但是我自己添加的却报错
Invalid bound statement (not found) : xx.xx.xx.selectByCustomerId
解决
搜了半天,检查了半天,跟网上说的没有半毛钱关系。。。
排除法
1. java方法名和id一致 ,没问题
2. 方法入参与parameterType一致,没问题
3. resultMap检查了没问题
4. sql写得有问题? 检查了无数次也没问题。。
好吧?!搜也不得答案,检查也没有问题,见鬼拉!?
检查一下target文件夹呢?
一看target文件夹里面的xml文件,nnd,果然没有我自己添加的那部分< id=”selectByCustomerId” >
估计是执行用例的时候是通过idea来执行的,而不会重新build项目。
执行下面的命令 ,先把target文件夹清掉
mvn clean
再执行
mvn test
target文件夹里的mapper.xml更新了,搞定!!!