错误 Parameter 'userId' not found. Available parameters are [arg1, arg0, param1, param2]"/>
使用Mybatis时发生的错误 Parameter 'userId' not found. Available parameters are [arg1, arg0, param1, param2]
做项目的时候,出现的一个小错误,刚开始还是为是Mapper接口写的参数名与XML中的SQL定义中取值时写的参数名不一致。后来发现我在Mapper接口文件中没有使用@Param注解。错误修正前,xml和Mapper中的代码如下:
xml中的SQL查询语句:
select
<include refid="Base_Column_List" />
from XXX
where u_id = #{uId,jdbcType=INTEGER}
and c_id=#{cId,jdbcType=INTEGER}
Mapper接口中的方法:
selectByUIdAndCId(Integer uId,Integer cId);
具体原因:因为涉及到mybatis 多参数映射,需要在Mapper接口中的方法参数加上@Param注解,此处要注意,要用mybatis的@Param,而不是Spring的@Param。如果用了Spring提供的@Param,也会报这个错。
selectByUIdAndCId(@Param("uId")Integer uId,@Param("cId")Integer cId);
这样就可以解决问题了。
更多推荐
使用Mybatis时发生的错误 Parameter 'userId' not found. Available parameters are
发布评论