使用Mybatis时发生的错误 Parameter 'userId' not found. Available parameters are [arg1, arg0, param1

编程入门 行业动态 更新时间:2024-10-14 12:23:32

使用Mybatis时发生的<a href=https://www.elefans.com/category/jswz/34/1771449.html style=错误 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

本文发布于:2024-03-06 09:20:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1714960.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   发生   userId   Parameter   Mybatis

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!