mybatisplus Mapper层绑定参数错误

,需要确保方法参数名与注解中的名称一致。参数的映射,无法正确绑定参数。MyBatis 默认的行为是。如果使用了具名参数(如。MyBatis 没有找到。

1
2
  @Update("update blog.user set mail=#{mail} where userId=#{userId}")
  void updateEncrypt(String mail, Long userId);

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘mail’ not found. Available parameters are [arg1, arg0, param1, param2]。

MyBatis 没有找到 mail 参数的映射,无法正确绑定参数。

MyBatis 默认的行为是通过位置来传递参数 (例如 arg0, arg1)。如果使用了具名参数(如 mailuserId),需要确保方法参数名与注解中的名称一致。有如下两种解决方法:

1
2
3
//使用 @Param 注解来明确指定参数名
@Update("UPDATE blog.user SET mail=#{mail} WHERE userId=#{userId}")
void updateEncrypt(@Param("mail") String mail, @Param("userId") Long userId);
1
2
3
//如果方法有多个参数,可以将这些参数封装成一个对象,然后通过该对象传递。
@Update("UPDATE blog.user SET mail=#{mail} WHERE userId=#{userId}")
void updateEncrypt(UserUpdateRequest request);
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计