解决使用mybatis做批量操作时发生的异常:Parameter '__frch_item_0' not found. Available parameters are [list] 记录
本文主要描述 使用mybatis进行批量更新、批量插入 过程中遇到的异常及总结:
首先贴出使用批量操作报的异常信息:
java.lang.RuntimeException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch_item_0' not found. Available parameters are [list]
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch_item_0' not found. Available parameters are [list]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)
最终查到导致异常的原因是 foreach中的属性字段名字写错了!表字段太多,一个个找的还是很费劲的!建议这种做好单元测试!
另外,写xml的时差错,还可以从下面几点检查。
1、parameterType="Java.util.List",这个parameterType有没有写错;
2、<foreach collection="list" item="item" index="index" open="" close="" separator=";">这行中,collection是不是List
关于批量更新做一个总结:
批量更新有两种,一种是通过id更新很多字段,第二种是更改一列,值是固定的这种。下面分别贴出列子
例子:
更新一列:
<update id="batchUpdateResult" parameterType="java.util.List">
update
<include refid="input_invoice_original_record" />
set isGet = 0 where invoiceNum in
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>
这种直接是item就行,只是一个查询的条件范围。
更新很多字段:
<update id="batchUpdate" parameterType="list">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update
<include refid="input_invoice_original_record" />
<trim prefix="SET" suffixOverrides=",">
<if test="item.title != null">
title = #{item.title},
</if>
<if test="item.invoiceNum != null">
invoiceNum = #{item.invoiceNum},
</if>
<if test="item.invoiceCode != null">
invoiceCode = #{item.invoiceCode},
</if>
<if test="item.invoiceDate != null">
invoiceDate = #{item.invoiceDate},
</if> </trim>
WHERE id = #{item.id}
</foreach>
</update>
注意,这种传的是一个个的对象在list集合中,要加item.属性名称,空判断的时候别忘记这种格式,这里我犯过错,没少费时间。
贴出来当时忘记加item的异常 信息:
java.lang.RuntimeException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'title' not found. Available parameters are [list]
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'title' not found. Available parameters are [list]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)
找这个问题用了不少时间!
下面说一下批量插入操作。
<insert id="batchInsert" parameterType="java.util.List"
useGeneratedKeys="true" keyProperty="id">
<selectKey resultType="long" keyProperty="id" order="AFTER">
SELECT
LAST_INSERT_ID()
</selectKey>
INSERT INTO
<include refid="input_invoice_original_record" />
(
title ,
invoiceNum,
invoiceCode,
invoiceDate,
sellDate ,
invoiceCategory
)
VALUES
<foreach collection="list" item="item" index="index"
separator=",">
(
#{item.title} ,
#{item.invoiceNum},
#{item.invoiceCode},
#{item.invoiceDate},
#{item.sellDate} ,
#{item.invoiceCategory}
)
</foreach>
</insert>
易错点和批量更新一样,写的时候要仔细。
这里做一个总结,如果不正确之处,欢迎指正!
解决使用mybatis做批量操作时发生的异常:Parameter '__frch_item_0' not found. Available parameters are [list] 记录的更多相关文章
- 使用DBCP时发生AbstractMethodError异常
使用DBCP时发生AbstractMethodError异常,错误描述: Exception in thread "main" java.lang.AbstractMethodEr ...
- SQL2008、SQL2013 执行Transact-SQL 语句或者批处理时发生了异常。错误5120
附加数据库的时候遇到问题,问题描述如下: 附加数据库 对于 服务器"服务器名"失败.(Microsoft.SqlServer.Smo) 执行Transact-SQL 语句或者批处理 ...
- mybatis 批量更新 Parameter '__frch_item_0' not found. Available parameters are [list]
一次在做批量更新数据的时候报错 Parameter '__frch_item_0' not found. Available parameters are [list] 记过反复查找,最后才发现是一个 ...
- 解决Parameter '__frch_item_0' not found. Available parameters 问题
1. 问题描述: 出现如下问题,执行报错信息 Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org ...
- mybatis 批量增加 Parameter '__frch_item_0' not found. Available parameters are [list]
当在mybatis用到foreach的时候,会报这个错误Parameter '__frch_item_0' not found. Available parameters are [list]会出现的 ...
- 记录一次排查使用HttpWebRequest发送请求的发生“基础连接已关闭:接收时发生错误”异常问题的过程
描述:某次更新程序,需要给测试员MM测试,之前都是正常的,更新后给MM测试就报异常System.Net.WebException 基础连接已经关闭:接收时发生错误 -------> System ...
- 解决win7远程桌面连接时发生身份验证错误的方法
远程桌面连接,是我们比较常用的一个功能了,但有时突然不能用了,以下是我遇到该问题,并解决该问题的方法.连接时报的是“发生身份验证错误,要求的函数不受支持”,解决之后细想一下,该问题好像是在我在电脑上安 ...
- 解决WCF跨机器调用时发生“调用方未由服务进行身份验证”的错误
1.服务器端Web.config配置文件,增加如下部分: <system.serviceModel> <bindings> <wsHttpBinding> < ...
- [转]ArcGIS for Silverlight:关于尝试连接到REST端点时发生安全异常的解决方案
Silverlight跨域策略: 要从远程服务器访问数据,远程服务器需要在 web 服务器的根目录下放置一个 clientaccesspolicy.xml 文件(例如 c:\inetpub\wwwro ...
随机推荐
- 深入浅出AOP(四)--AOP的实现步骤
AOP是什么?有什么用处?怎么实现?在前面的博客中已经写的非常具体了,那么我们怎么一步一步考虑的呢? 在最初的时候,我们知道AOP是一个拦截业务.提供服务的东西.于是我们是这样做的: 后来又了加上了S ...
- Windows下批处理命令启动项目bat脚本
文件env.cfg #server name SERVER_NAME=ActivitiService #JDK Home JDK_HOME= #Main MAIN_CLASS=com.nbtv.com ...
- 2017.3.27 集成modeler后的一些主要路径(持续更新)
1.设计器访问路径 项目名:wfs_web edtor-app和modeler.html的存放位置:webapp/designer/editor-app app-cfg.js中根路径设置:'conte ...
- 2016.7.12 在navicat中用sql语句建表
参考资料: http://jingyan.baidu.com/article/f0e83a25a8c4b022e5910116.html 即新建query,然后run. (1)点击要新建表的位置,选择 ...
- WCF TCP通信方式 通过IIS承载调试
http://www.cnblogs.com/nikymaco/archive/2012/10/08/2715954.html IIS Express服务器只支持http/https,不支持net.t ...
- curl库pycurl实例及参数详解
pycurl是功能强大的python的url库,是用c语言写的,速度很快,比urllib和httplib都快. 今天我们来看一下pycurl的用法及参数详解 常用方法: pycurl.Curl() # ...
- leetCode 83.Remove Duplicates from Sorted List(删除排序链表的反复) 解题思路和方法
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- PHP第四课 了解经常使用的函数
学习概要: 一.语言结构 二.自己定义函数 三.变量作用域 四.静态变量 五.函数返回值 六.參数 七.默认參数 八.引用參数 九.可变个数函数 十.回调函数 十一.变量函数 十二.递归函数 十三.文 ...
- 一文了解ConfigurationConditon接口
ConfigurationCondition 接口说明 @Conditional 和 Condition 在了解ConfigurationCondition 接口之前,先通过一个示例来了解一下@C ...
- Android-Animations介绍
一.Animations介绍 Animations是一个实现android UI界面动画效果的API,Animations提供了一系列的动画效果,可以进行旋转.缩放.淡入淡出等,这些效果可以应用在绝大 ...