Parameter 'xxx' not found. Available parameters are [0, 1, param1, param2]报错
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码
MyBatis使用过程中遇到报错:
nested exception is org.apache.ibatis.binding.BindingException: Parameter 'groupId' not found. Available parameters are [arg1, arg0, param1, param2]
mapper.xml映射没有得到传入的参数。
在使用mybatis开发的时候,有时候需要传入多个参数进行查询,当传入多个参数时,需要用到@Param
注解。
错误时:
@Insert("insert into classgroup (classId, groupId) values (#{classId}, #{groupId})")
int insert(Integer classId, Integer groupId);
添加注解后不再报错:
@Insert("insert into classgroup (classId, groupId) values (#{classId}, #{groupId})")
int insert(@Param("classId")Integer classId, @Param("groupId")Integer groupId);
注:当参数只有一个时,可以不使用@Param注解。