问题描述: 使用mybatis框架做增删改查操作时报错,详细错误信息为:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed;
nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘num’ not found. Available parameters are [0, 1, param1, param2]] with root cause
接口中报错的方法:
@Update("update goods set num=#{num} where id=#{id}")
int updateGoods(int id, String num);
错误原因: 参数为对象时才通过#{对象属性名}的方式取值,这里要使用#{0}或#{param1}的形式
问题解决: 【[mybatis] 异常Available parameters are [0, 1, param1, param2]] with root cause解决】修改为:
@Update("update goods set num=#{1} where id=#{0}")
int updateGoods(int id, String num);