解决使用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 ...
随机推荐
- sublime text常用快捷键(转)
选择一个选中项的下一个匹配项: ctrl+d 把光标放在一个单词上,按下ctrl+ D,将选择这个单词.一直按住ctrl且按D多次,将选择当前选中项的下一个匹配项.通过按住ctrl,再按D三次,将选择 ...
- OpenSceneGraph-3.3.3
OpenSceneGraph-3.3.3, [/b]released on 19th December 2014, key deliverables in this dev release are: ...
- Python moni模拟鼠标事件
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 4 ...
- 白盒测试中如何实现真正意义上并发测试(Java)
在这个话题开始之前,首先我们来弄清楚为什么要做并发测试? 一般并发测试,是指模拟并发访问,测试多用户并发访问同一个应用.模块.数据时是否产生隐藏的并发问题,如内存泄漏.线程锁.资源争用问题. 站在性能 ...
- hdu2955 Robberies (01背包)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=2955">http://acm.hdu.edu.cn/showproblem.php ...
- python:字符串的连接
python中有很多字符串连接方式,今天在写代码,顺便总结一下: 最原始的字符串连接方式:str1 + str2 python 新字符串连接语法:str1, str2 奇怪的字符串方式:str1 st ...
- VueJS自定义全局和局部指令
除了默认设置的核心指令( v-model 和 v-show ), Vue 也允许注册自定义指令. 使用directive自定义全局指令 下面我们注册一个全局指令 v-focus, 该指令的功能是在页面 ...
- ORACLE schedule job设置
--创建job begin DBMS_SCHEDULER.CREATE_JOB ( job_name => 'APICALL_LOG_INTERFACE_JOB', job_type => ...
- URL Handle in Swift (二) — 响应链处理 URL
最后更新: Swift4时候的博客,以前在 CMD markdown 上编辑的,现在搬到这里 在上篇文章-URL Handle in Swift (一) -- URL 分解中,我们已经将URL进行了分 ...
- AndroidX86模拟器Genymotion的一些使用和另一款Andy模拟器
命令行启动虚拟机 当我们下载安装好,可以通过命令行运行指定名字模拟器 D:\ProgramFiles\Genymobile\Genymotion\player --vm-name "Sam ...