开发者社区 问答 正文

mybatis froeach循环报错?报错

mybatis xml:

<select id="getList" parameterType="list" resultMap="BaseResultMap">
    select * from tbl 
    <where>
      and id in 
      <foreach collection="list" item="item" open="(" 
           separator="," close=")">
           #{item}
      </foreach>
    </where>
</select>


java :

List<Long> idlist = new ArrayList<Long>();
idlist.add(1L);
idlist.add(21L);
List<vo> l = dao.selectList("getList", idlist);  

ERROR:
org.apache.ibatis.binding.BindingException: Parameter 'needMeta' not found. Available parameters are [collection,list]  


mybatis froeach 为什么会报错?哪里写错了吗?

展开
收起
爱吃鱼的程序员 2020-06-08 11:38:03 419 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    只有close应该还有(吧

    dao.selectList("getList",idlist)

    这个selectList方法的第二个形参,参数名称是什么? 是needMeta吗?如果不是,请换个名字让他和mapperxml里面的变量名一致,或者是,给这第二个形参加一个注解@Param("needMeta")。

    试试看吧。

    根据mybatis的API,直接传入LIST,会自动包装成一个list为Key值的map,在XML中直接用list来获取
    <selectid="getList"resultMap="BaseResultMap">select*fromtbl<where>andidin<foreachcollection="list"item="item"open="("separator=","close=")">#{item}</foreach></where></select>
    试过了,一样的错误信息去掉参数类型试试

    2020-06-08 11:38:22
    赞同 展开评论