Parameter ‘ids‘ not found. Available parameters are [array, arg0]

Parameter ‘ids’ not found. Available parameters are [array, arg0]

mabaties在批量删除,接收数组或者集合时,写法是不同的

接收数组

错误写法

int deleteCoinvoiceInfoByCoids(@Param("ids") Long[] ids);
<update id="deleteCoinvoiceInfoByCoids" >
        update base_coinvoice_info set del_flag='1'
        where del_flag='0'
            and coid in
            <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
                ${item}
            </foreach>
  </update>

正确写法

<update id="deleteCoinvoiceInfoByCoids" >
     update base_coinvoice_info set del_flag='1'
      where del_flag='0'
          and coid in
          <foreach collection="array" item="item" index="index" open="(" separator="," close=")">
              ${item}
          </foreach>
  </update>

接收集合list

错误写法

int deleteCoinvoiceInfoByCoids(@Param("ids") List<long> ids);
<update id="deleteCoinvoiceInfoByCoids" >
        update base_coinvoice_info set del_flag='1'
        where del_flag='0'
            and coid in
            <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
                ${item}
            </foreach>
  </update>

正确写法

<update id="deleteCoinvoiceInfoByCoids" >
        update base_coinvoice_info set del_flag='1'
        where del_flag='0'
            and coid in
            <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
                ${item}
            </foreach>
  </update>

原因

当mybatis传入参数为list集合的时候;mybatis会自动把其封装为一个map;会以“list”作为key;每个元素的值作为value;格式为 Map<“list”,value>

当mybatis传入参数为数组的时候mybatis会自动把其封装为一个map;会以“array”作为key;每个元素的值作为value;格式为Map<“array”,value>

上一篇:C# 基础 - 日志捕获二使用 log4net


下一篇:《HTML5实战》—A.4 紧跟规范的最新进展