Mybatis报错:Parameter 'list' not found. Available parameters are [groupList, param1]

GroupDao.java 里面定义的方法:

void batchInsertLog(@Param("groupList") List<MktPromotionIntegralLog> groupList);

修改前的GroupMapper.xml

<insert id="batchInsertLog" parameterType="java.util.List">
  INSERT INTO table
  (ps_id,goods_id,item_number,goods_name)
  values
  <foreach collection="list" item="log" index="groupList" separator=",">
    (#{log.ps_id},#{log.goods_id},#{log.item_number},#{log.goods_name})
  </foreach>
</insert>

执行batchInsertLog方法会报错:

Parameter 'list' not found. Available parameters are [groupList, param1]

修改后的GroupMapper.xml

<insert id="batchInsertLog" parameterType="java.util.List">
  INSERT INTO table
  (ps_id,goods_id,item_number,goods_name)
  values
  <foreach collection="groupList" item="log" index="groupList" separator=",">
    (#{log.ps_id},#{log.goods_id},#{log.item_number},#{log.goods_name})
  </foreach>
</insert>

修改后报错问题得以解决.

产生这个问题的原因是由于一直认为 foreach 里面的 collection 应该放的是 java.util.List 之类的,但其实应该是我们与Dao里面 @Param("groupList")  绑定的参数名一致,如果没有使用 @Param ,修改前的修改前的GroupMapper.xml也是不会有问题的.

上一篇:8.Lucene多字段搜索


下一篇:three.js学习笔记--基础知识