mybatis异常:nested exception is org.apache.ibatis.binding.BindingException
mybatis异常:nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘userI’ not foun
在使用mybatis开发的时候,有时候需要传入多个参数进行查询,当传入多个参数时,不会处理会出现下面异常:
nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘userId’ not found. Available parameters are [0, 1, param1, param2]
出现上面异常的原因是*mapper.xml映射没有得到传入的参数,这个时候需要在DAO变化传参,下面对比一下错误的和正确的传参方式:
错误原因1 传递多个参数没有添加@Param 注解
错误的
public List<EquipmentUser> findEquipmentUserInfoBySystemUserId(Integer userId, String equipmentType);
要使用@Param(“userId”)注解进行传参,才能让*mapper.xml文件得到参数,
正确的写法如下:
public List<EquipmentUser> findEquipmentUserInfoBySystemUserId(@Param("userId")Integer userId, @Param("equipmentType")String equipmentType);
错误原因2 @Param 注解导错了包
注意: 有的开发者即使使用了@Param注解,还是会报这个异常,原因是在导包的时候,导入的是spring的@Param的注解包,在这里我们需要导入mybatis的@Param注解包,也就是org.apache.ibatis.annotations.Param;这个包
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_43593107/article/details/121136995
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐



所有评论(0)