Mybatis——必须使用@param注解 2021年6月19日

建议在使用Mybatis时,一定要加上@param注解

踩了一个坑,报错为:

aused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'flowId' not found. Available parameters are [arg1, arg0, param1, param2]
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)

解决方法为在使用Mybatis时,加上@Param注解,否则尽管在接口中定义了参数的名称,mybatis仍然不认识:


@Repository
public interface MMMDao extends Mapper<AAA> {
List<AAA> selectByFlowRuleId(@Param(value="flowId") Long flowId, @Param(value="ruleId") Long ruleId);
}
原文地址:https://www.cnblogs.com/jingbostar/p/14902490.html