项目中MyBatis报错如下:
nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'keyword' not found. Available parameters are [arg2, arg1, arg0, param3, param1, param2]] with root cause
1. 问题复现① Controller层:
@GetMapping("/listCanStart")
public List listCanStart(
@RequestParam(value = "searchKey", required = false) String searchKey,
@RequestParam(value = "businessType") String businessType,
@RequestParam(value = "businessCategory" , required = false) String businessCategory
) {
return this.processDefinitionService.listCanStart(searchKey, businessType, businessCategory);
}
② Dao层:
@Mapper public interface ProcdefTagMapper extends BaseMapper{ List getProcDefIdByNameOrTagThatCanStart( String keyword, String businessType, String businessCategory); }
select PROCDEF.ID_ from ACT_RE_PROCDEF PROCDEF join T_PROCDEF_TAG TAG PROCDEF.ID_ = TAG.PROCDEF_ID_ order by FIELD( TAG_, #{businessType} ) DESC;and PROCDEF.NAME_ like CONCAt('%',#{keyword},'%') and TAG.TAG_ = #{businessCategory}
结果运行出现报错:nested exception is org.apache.ibatis.binding.BindingException: Parameter 'keyword' not found. Available parameters are [arg2, arg1, arg0, param3, param1, param2]] with root cause
这个问题涉及到MyBatis3在使用select节点查询时传递多个参数的问题。
2. 解决方法解决方法不止一种,下面使用 @Param注解解决,即只有一个参数时,可以不使用@Param注解,但是方法中有多个参数时需要使用@Param注解在这里插入代码片。
@Mapper public interface ProcdefTagMapper extends BaseMapper{ List getProcDefIdByNameOrTagThatCanStart( @Param("keyword") String keyword, @Param("businessType") String businessType, @Param("businessCategory") String businessCategory); }



