likes
comments
collection
share

Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.

作者站长头像
站长
· 阅读数 12

你们好,我是金金金。

Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.

场景

Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.

  • 在使用Mybatis操作sql语句过程当中,更新操作,报错信息如下:Caused by: org.apache.ibatis.binding.BindingException: Parameter 'empId' not found. Available parameters are [arg1, arg0, param1, param2],未找到参数“empId”。 可用参数为 [arg1, arg0, param1, param2]

附上代码

  • mapper接口 Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.
  • mapper.xml文件 Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.
  • test Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.

排查

  • 从报错信息得知:可用参数为[arg1, arg0, parma1, param2],mybatis底层是做了处理的,这种写法是识别不到你自定义写的字段的,可以使用arg0,或者parma1来替代使用,arg0代表的是第一个参数,parima则是从1开始。

我这里就测试arg0和arg1这种方式了。

Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.

Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.

可以看到没有任何问题,但是不推荐上面这种写法,参数多了容易混淆,导致蒙蔽,以下有一种更好的写法,请继续往下看

解决

  • 使用@Param注解标记方法参数,明确指定参数的名称,这样xml文件就可以识别到了

Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.

Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.

测试

Mybatis操作sql报错ibatis.binding.BindingException: Parameter 'empId' not found.

没毛病!!!

  • 编写有误还请大佬指正,万分感谢。
转载自:https://juejin.cn/post/7344916114204147749
评论
请登录