org.apache.ibatis.binding.BindingException: Parameter 'ids' not found. Available parameters。。。

参考文章 http://www.cnblogs.com/caoyajun33-blog/p/6875169.html

在学习mybatis的时候,使用foreach遍历集合,出现如标题一样的错误

### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: 
    Parameter 'ids' not found. Available parameters are [collection, list]

接口代码:

public interface EmployeeMapperDynamicSQL {
    
    //根据多个id查询
    public List<Employee> getEmpsByConditionForeach(List<Integer> ids) ;
}

xml代码:

<!-- public List<Employee> getEmpsByConditionForeach(List<Integer> ids) -->
    <select id="getEmpsByConditionForeach" resultType="com.atguigu.bean.Employee">
<!--         select * from tbl_employee where id in(1,2,3) 用foreach标签处理-->
        select * from tbl_employee where id in
	        <!-- 
	            collection:指定要遍历的集合,
	                list类型的参数会特殊处理封装在map中,map的key就叫list
	            item:将当前便利出的元素赋值给指定的变量
	            separator:每个元素之间的分隔符
	            open:遍历出所有结果拼接一个开始的字符
	            close:遍历出所有结果拼接一个结束的字符
	            index:索引。遍历list的时候index是索引,item是当前值
	                                                         如果遍历map,index表示的就是map的key,item就是map的值
	            #{变量名}:能取出变量的值,也就是当前遍历出的元素
	         -->
	        <foreach collection="ids" item="item_id" separator="," open="(" close=")">
	            #{item_id}
	        </foreach> 
    </select>

collection里我填的是ids,然后就报了找不到ids的错误。后来看了一下别人的解释和老师给的讲解注释,发现是

collection:指定要遍历的集合,
	                list类型的参数会特殊处理封装在map中,map的key就叫list

key是list,所以改成list就正常执行了。

over

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值