本文主要描述 使用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] 记录的更多相关文章

  1. 使用DBCP时发生AbstractMethodError异常

    使用DBCP时发生AbstractMethodError异常,错误描述: Exception in thread "main" java.lang.AbstractMethodEr ...

  2. SQL2008、SQL2013 执行Transact-SQL 语句或者批处理时发生了异常。错误5120

    附加数据库的时候遇到问题,问题描述如下: 附加数据库 对于 服务器"服务器名"失败.(Microsoft.SqlServer.Smo) 执行Transact-SQL 语句或者批处理 ...

  3. mybatis 批量更新 Parameter '__frch_item_0' not found. Available parameters are [list]

    一次在做批量更新数据的时候报错 Parameter '__frch_item_0' not found. Available parameters are [list] 记过反复查找,最后才发现是一个 ...

  4. 解决Parameter '__frch_item_0' not found. Available parameters 问题

    1. 问题描述: 出现如下问题,执行报错信息 Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org ...

  5. mybatis 批量增加 Parameter '__frch_item_0' not found. Available parameters are [list]

    当在mybatis用到foreach的时候,会报这个错误Parameter '__frch_item_0' not found. Available parameters are [list]会出现的 ...

  6. 记录一次排查使用HttpWebRequest发送请求的发生“基础连接已关闭:接收时发生错误”异常问题的过程

    描述:某次更新程序,需要给测试员MM测试,之前都是正常的,更新后给MM测试就报异常System.Net.WebException 基础连接已经关闭:接收时发生错误 -------> System ...

  7. 解决win7远程桌面连接时发生身份验证错误的方法

    远程桌面连接,是我们比较常用的一个功能了,但有时突然不能用了,以下是我遇到该问题,并解决该问题的方法.连接时报的是“发生身份验证错误,要求的函数不受支持”,解决之后细想一下,该问题好像是在我在电脑上安 ...

  8. 解决WCF跨机器调用时发生“调用方未由服务进行身份验证”的错误

    1.服务器端Web.config配置文件,增加如下部分: <system.serviceModel> <bindings> <wsHttpBinding> < ...

  9. [转]ArcGIS for Silverlight:关于尝试连接到REST端点时发生安全异常的解决方案

    Silverlight跨域策略: 要从远程服务器访问数据,远程服务器需要在 web 服务器的根目录下放置一个 clientaccesspolicy.xml 文件(例如 c:\inetpub\wwwro ...

随机推荐

  1. API接口管理工具postman等

    国外 postman Swagger:国外比较流行的一款管理工具,英文配置,需要一定的英文基础和服务器搭建基础,学习成本较高. 国内 Apizza: 风格类似postman,熟悉postman的会比较 ...

  2. log4j.properties(信息打印)

    ### set log levels ###log4j.rootLogger = INFO , console , debug , error ### console ###log4j.appende ...

  3. HTML5 Canvas 绘制澳大利亚国旗

    代码: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type ...

  4. uboot下netconsole的原理及用法

    近期发现uboot下一个非常有意思也非常有用的功能:netconsole,uboot下的netconsole相似于kernel下的telnet等网络终端功能,将网络作为输入输出的终端,这样就便于我们在 ...

  5. es6 - 导入导出

    今天用node纠结了半天,明明是正确的语法,一直报错,原来node和chrome并不支持es6语法.... 1. npm install package.json { "name" ...

  6. 【Excle数据透视】如何用含有单元格的数据来创建数据透视

    取消合并单元格,填充相同内容项,然后创建数据透视表. 如下图:需要使用数据创建数据透视表 步骤一 开始→格式刷,然后对单元格区域G2:G15使用格式刷功能,保留合并单元格格式 步骤二 选中A2:A18 ...

  7. java个人感想

    java与c++相比,摒弃了c++的指针,把c++中的stl封装成一个库,而且改变了当中的某些方法,使用方法也产生了非常多不同,读者在编程过程中须要自己细细体会 个人觉得三大框架基于前端+领域逻辑+数 ...

  8. Web Service之Soap请求响应内容中文编码解密

    java模拟Soap请求测试Web Service接口,发现Web Service响应内容中的中文竟然是编码格式.比如: 中文:退保成功 Soap中文编码:退保成功   我仔细分析后发现,退编码实际上 ...

  9. C# 嵌入dll 动软代码生成器基础使用 系统缓存全解析 .NET开发中的事务处理大比拼 C#之数据类型学习 【基于EF Core的Code First模式的DotNetCore快速开发框架】完成对DB First代码生成的支持 基于EF Core的Code First模式的DotNetCore快速开发框架 【懒人有道】在asp.net core中实现程序集注入

    C# 嵌入dll   在很多时候我们在生成C#exe文件时,如果在工程里调用了dll文件时,那么如果不加以处理的话在生成的exe文件运行时需要连同这个dll一起转移,相比于一个单独干净的exe,这种形 ...

  10. POJ 2985 Treap平衡树(求第k大的元素)

    这题也能够用树状数组做,并且树状数组姿势更加优美.代码更加少,只是这个Treap树就是求第K大元素的专家--所以速度比較快. 这个也是从那本红书上拿的模板--自己找了资料百度了好久,才理解这个Trea ...