一、错误显示
Caused by: org.apache.ibatis.binding.BindingException: Parameter '__frch_item_0' not found. Available parameters are [list]
at org.apache.ibatis.session.defaults.DefaultSqlSession$StrictMap.get(DefaultSqlSession.java:261)
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:44)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)
at org.apache.ibatis.reflection.MetaObject.metaObjectForProperty(MetaObject.java:138)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:109)
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:76)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62)
at com.sun.proxy.$Proxy51.parameterize(Unknown Source)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:47)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
... 49 more
二、 由来
mybatis批量insert,数据库mysql
<insert id="batchInsertMaterielReceived" parameterType="java.util.List" useGeneratedKeys="false">
insert into materiel_received (merchant_id, produce_bill_id, `status`,
create_time, modify_time, creater_mid, updater_mid,
m_product_id, m_product_sku_id, `name`,
specification, num_received, num_used,
num_rest, unit_name, supplier_id,
supplier_name, remark, storage_out_id,
process_produce_id, process_type_id, user_mid,
user_name)
values<foreach collection="list" item="item" index="index" separator=",">
(#{item.merchantId,jdbcType=BIGINT},
#{item.produceBillId,jdbcType=BIGINT},
#{item.status,jdbcType=CHAR},
sysdate(),
sysdate(),
#{item.createrMid,jdbcType=BIGINT},
#{item.updaterMid,jdbcType=BIGINT},
#{item.mProductId,jdbcType=BIGINT},
#{item.mProductSkuId,jdbcType=BIGINT},
#{item.name,jdbcType=VARCHAR},
#{item.specification,jdbcType=VARCHAR},
#{item.numReceived,jdbcType=BIGINT},
#{item.numUsed,jdbcType=BIGINT},
#{item.numRest,jdbcType=BIGINT},
#{item.unitName,jdbcType=VARCHAR},
#{item.supplierId,jdbcType=VARCHAR},
#{item.supplierName,jdbcType=VARCHAR},
#{item.remark,jdbcType=VARCHAR},
#{item.storageOutId,jdbcType=BIGINT},
#{item.processProduceId,jdbcType=BIGINT},
#{item.processTypeId,jdbcType=BIGINT},
#{item.userMid,jdbcType=BIGINT},
#{item.userName,jdbcType=VARCHAR}
)
</foreach>
</insert>
三、解决方法
’ 说实话,为什么会有这样的报错,给点提示行不行?上网查了一堆,答案都差不多,什么parameterType="java.util.List",什么collection="list,说的都差不多,其实我只是单词写错了。。。。。。item.supplierName里的supplierName写错了。。。。。
为什么要显示这个错误,就不能显示清楚点吗
其实我们一些基础的都知道 ,往往都是因为一些小的拼写错误而否定自己所学的,一遍一遍的改,改list,增加@param等等,
刻意否定自己,到最后发现其实没有错,指不定只是哪个单词写错了,哪个标点忘记写或者写多了
四、心得
如果觉得自己的语法格式等没错,不要急着否定自己,不要急着改,不要急着尝试第二种解法、第三种解法,静下心来好好地仔细检查一下,特别是表的字段很多的时候,要有耐心。(也是对自己说的)
程序员的生活本就无趣,所以同学们,不要整天宅在家里打游戏,约几个朋友出去走一走,看一看外面的风景,一天下来你会发现。。。。。。。。。。还不如坐在家里打游戏 !
本文详细解析了在使用MyBatis进行批量插入操作时遇到的BindingException异常,通过一个具体的XML映射文件示例,揭示了问题根源在于参数名称的拼写错误,并分享了解决此类问题的心得体会。
8万+

被折叠的 条评论
为什么被折叠?



