栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

MyBatis - 使用@Param注解解决mybatis方法传入多参数时的报错问题

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MyBatis - 使用@Param注解解决mybatis方法传入多参数时的报错问题

项目中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_
        
            and PROCDEF.NAME_ like  CONCAt('%',#{keyword},'%')
        
        
            and TAG.TAG_ = #{businessCategory}
        
    
    order by
    FIELD( TAG_, #{businessType} ) DESC;

结果运行出现报错: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);
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/894756.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号