• Parameter 'idList' not found. Available parameters are [collection,list]


    1、nested exception is org.apache.ibatis.binding. BindingException : Parameter 'idList' not found. Available parameters are [collection,list] 

    这个错误原因有多个:

    (1)检查mapper(或dao)写的方法参数有没有绑定,如:

    List<Aaa> queryByIdList(@param("idList")List<String>idList);

    如果,没有@param("idList"),那么在mapper.xml里面用到idList则会报上面的异常。

    当然也可以不需要写@param("idList"),这样的话需要在mapper.xml里面用到时是这样用的:

    <if test="list!=null and list.size>0">
        and id in
        <foreach item="item" index="index" collection="list" open="(" close=")"  separator=",">
        #{item}
      </foreach>
    </if>

    用collection="list" 而不是 collection="idList",这是因为当只传一个集合或者数组作为参数时,mybatis会讲其包装到Map中,集合会以“list”作为键,数组会以“array”作为键。

    (2)检查param的包有没有导错,正确的包应该是org.apache.ibatis.annotations.Param,其实报错已经提示了:nested exception is org.apache.ibatis.binding

    我就是导错包了,我导入的包是org.springframework.data.repository.query.Param,导致的报错。

    2、Error querying database. xxxx:invalid comparison:java.util.ArrayList and java.lang.String

    这个错误是mapper.xml中集合判空用了 idList !='' 导致的,其实跟java写法一样就可以了,如:

    <if test="list!=null and list.size>0">xxx</if>
    或者
    <if test="list!=null and list.size()>0">xxx</if>

    3、补充一下mybatis常用传参方式

    (1)只有一个参数,可以不需要@Param。

    如:Aaa queryAaa(String aa);

    Select * from aaa_info where aa_status=#{aa}

    (2)直接传对象,如:

    dao的接口方法:List<Aaa> queryAaaList(AaaParam aaaParam);

    mapper.xml中直接用AaaParam类中的属性就可以了。

    比如AaaParam有属性aaStatus、aaBb、aaCc,那么可以直接在mapper.xml中使用如:Select * from aaa_info where aa_status=#{aaStatus} and aa_bb=#{aaBb} and aa_cc=#{aaCc}

     (3)使用@Param绑定

    如:List<Aaa> queryAaaList(@Param("dto")AaaParam aaaParam);

    那么在xml中使用:Select * from aaa_info where aa_status=#{dto.aaStatus} and aa_bb=#{dto.aaBb} and aa_cc=#{dto.aaCc}

    不一一列举了。

  • 相关阅读:
    Android Shape画圆,矩形
    Android 图片平铺效果实现的3种方法
    threadid=1: thread exiting with uncaught exception (group=0x40db8930)
    Facebook 调试工具Stetho配置入门
    Exception in MessageQueue callback: handleReceiveCallback
    EditText 双击才能获取点击事件
    2011年中国(大陆)地级以上(含省直辖县)行政区划表
    Android 应用接入广点通统计API 方案
    Android常用工具类封装---SharedPreferencesUtil
    IIS上发布站点后URL重写失效的解决方法
  • 原文地址:https://www.cnblogs.com/pzw23/p/15919993.html
Copyright © 2020-2023  润新知