org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingExce

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘list’ not found报错

在这里插入图片描述
使用mybatis时遇到此错误怎么解决。报错原因是:它说下面代码中的
<foreach collection=“list” 这个list没有找到。

 <insert id="insertList" parameterType="java.util.List">
        INSERT propertyValue(propertyValue_id,propertyValue_value,propertyValue_property_id,propertyValue_product_id)
        VALUES    
        <foreach collection="list" index="index" item="propertyValue" separator=",">
            (null,
            #{propertyValue.propertyValue_value},
            #{propertyValue.propertyValue_property.property_id},
            #{propertyValue.propertyValue_product.product_id})
        </foreach>
    </insert>

但在dao层方法中我们确实是传了一个list集合类型的参数过去

 Integer insertList(@Param("propertyValue_list") List<PropertyValue> propertyValueList);

按照mybatis的约定
collection:表示dao层方法传来的参数类型.
如果是数组:collection=“array“
list集合:collection=”list”
set集合:collection=“set”
map集合:collection=“该map集合key的名字”

解决方法是:
1、因为我们对参数起了别名@Param(“propertyValue_list”),所有在sql语句中应该写 collection =”propertyValue_list“

 <insert id="insertList" parameterType="java.util.List">
        INSERT propertyValue(propertyValue_id,propertyValue_value,propertyValue_property_id,propertyValue_product_id)
        VALUES    
        <foreach collection="propertyValue_list" index="index" item="propertyValue" separator=",">
            (null,
            #{propertyValue.propertyValue_value},
            #{propertyValue.propertyValue_property.property_id},
            #{propertyValue.propertyValue_product.product_id})
        </foreach>
    </insert>

2、或者在dao层的方法中 Integer insertList(List propertyValueList);
去掉@Param(“propertyValue_list”)
测试结果通过:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值