一、异常
org.apache.ibatis.binding.BindingException: Parameter ‘xxxxxx’ not found. Available parameters are [arg1, arg0, param1, param2]
二、解释
1)BindingException:绑定异常
2)Parameter ‘xxxxxx’ not found:参数xxxxxx找不到
3)Available parameters…:可用的参数……
三、解决
其实异常提醒已经很明显了。
1、参数名字写错了
例如,List<Student> testWhere(String snmae);
2、传递了多个参数,混淆了,需要使用@Param标签指定
例如,List<Student> testWhere(@Param("aaa") String sname,@Param("bbb") String semail);
四、@Param补充
标签@Param中的名称aaa表示sname;bbb表示semail。所以使用的sname、semail的时候就用aaa、bbb代替。
一般标签中的名称和参数名称一致,这里为了解释取了其他怪异的名称做区分。
<select id="testWhere" resultMap="BaseResultMap">
select sid,sname,sage,ssex,semail from student
<where>
<if test="aaa!=null">sname like concat('%',#{aaa},'%')</if>
<if test="bbb!=null">
<![CDATA[and semail like concat('%',#{bbb},'%')]]>
</if>
</where>
</select>