当先锋百科网

首页 1 2 3 4 5 6 7

使用mybatis批量操作数据时,输出如下异常:

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

原因是mybatis没有找到对应的集合名称,下为原配置:

int insertTestObjects( List<TestObject> objectList);
<insert id="insertTestObjects" parameterType="com.xxx.TestObject">
        insert into testObject (o_id,o_type, create_time)
        values
        <foreach collection="objectList" item="item" separator=",">
            (#{item.oId,jdbcType=BIGINT}, #{item.oType,jdbcType=INTEGER},
             #{item.createTime,jdbcType=TIMESTAMP})
        </foreach>
    </insert>

可以

1.修改mapper的方法参数

int insertTestObjects(@Param("objectList") List<TestObject> objectList);

或者 

2.

<insert id="insertTestObjects" parameterType="com.xxx.TestObject">
        insert into testObject (o_id,o_type, create_time)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.oId,jdbcType=BIGINT}, #{item.oType,jdbcType=INTEGER},
             #{item.createTime,jdbcType=TIMESTAMP})
        </foreach>
    </insert>

 

 

参考:https://www.cnblogs.com/caoyajun33-blog/p/6875169.html