Parameter 'xxx' not found. Available parameters are [arg1, arg0, param1, param2]
2021/8/3 23:37:11
本文主要是介绍Parameter 'xxx' not found. Available parameters are [arg1, arg0, param1, param2],对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
问题:
org.mybatis.spring.MyBatisSystemException:nested exception is org.apache.ibatis.binding.BindingException: Parameter 'xxx' not found. Available parameters are [arg1, arg0, param1, param2]
原因:
这个问题是因为我们在Mapper接口中声明方法的时候有多个参数,例如:
Mapper接口中方法:
int selectUser(String pid,String pname);
然后在mapper.xml配置如下:
<select id="selectUser" resultType="xxx.xxx.xxx.model.User">
select *
from user
where id = #{pid} and name = #{pname}
</select>
这样直接用pid,pname就会报错的。
解决方法:
这里使用@Param注解,这种方式Mybatis就会自动将参数封装成Map类型,@Param注解的值会作为Map中的key,例如:
Mapper接口中:
int selectUser(@Param("pid")String pid,@Param("pn")String pname);
mapper.xml中:
<select id="selectUser" resultType="xxx.xxx.xxx.model.User">
select *
from user
where id = #{pid} and name = #{pn}
</select>
这里注意一下:
@Param(“pn”) String pname,@Param里面的定义的名称(即pn)可以和参数名(即pname)不一致。在xml中的SQL 语句是以“pn”作为key的。也就是说在使用时是 name = #{pn},而不是 name = #{pname}了。
这篇关于Parameter 'xxx' not found. Available parameters are [arg1, arg0, param1, param2]的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-29蓝桥杯大赛单片机比赛经验总结
- 2024-05-29AI 一键生成高清短视频,视频 UP 主们卷起来...
- 2024-05-29打造 AI “看牙”新体验,当 Serverless 遇上口腔医疗
- 2024-05-27取代或转型?人工智能对软件测试的影响(内附工具推荐)
- 2024-05-14让创意在幻觉中肆虐: 认识Illusion Diffusion AI
- 2024-05-08Sora从入门到入门-白话版1
- 2024-05-082024年github开源top100中文
- 2024-05-083、最大池化maxinmum pooling
- 2024-05-08动态规划基础思想
- 2024-05-08Kimi:文本解析利器,你相信光么?