ibatis遍历数组对象时,填写不全,容易报错。以下情况就经常遇到问题。

     <isNotNull property="typeList" prepend=" AND "><iterate property="typeList" conjunction="OR" open="(" close=")">type = #typeList[]#</iterate></isNotNull>

如上,遍历对象时,必须把上面信息写全面,如果发生遗漏,容易报错。
情况1:

<isNotNull property="typeList" prepend=" AND "><iterate conjunction="OR" open="(" close=")">type = #typeList[]#</iterate>
</isNotNull>

如果iterate中不写明对象名称,必然要进行报错。如下:

--- Cause: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or property was not a Collection, Array or Iterator.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in ibatis/sqlmap/user.xml.
--- The error occurred while preparing the mapped statement for execution.
--- Check the StockRunLog.getStockRunLogListCount.
--- Check the parameter map.
--- Cause: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or property was not a Collection, Array or Iterator.
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];   

根据错误,还是很好识别的。
情况2:

<isNotNull property="typeList" ><iterate property="typeList" conjunction="OR" open="(" close=")">type = #typeList[]#</iterate>
</isNotNull>

当缺少apend时,造成上个字段和遍历字段无连接词,会报错。如下:

--- The error occurred while applying a parameter map.
--- Check the StockRunLog.getStockRunLogListCountMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(                 type = 10             OR                 type = 11            ' at line 1]; SQL was [] for task [SqlMapClient operation]
2016-09-19 21:33:46 DEBUG [DataSourceUtils.java:327]  - Returning JDBC Connection to DataSource
2016-09-19 21:33:46 DEBUG [PreparedStatementPool.java:123]  - {conn-10005, pstmt-20022} enter cache
2016-09-19 21:33:46 DEBUG [AbstractHandlerExceptionResolver.java:132]  - Resolving exception from handler [public com.zsx.reponse com.zsx.web.controller.stock.StockRunLogController.getStockRunLogList(java.lang.Long,java.lang.Long,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Long,java.lang.Long,java.lang.Integer,java.lang.Integer) throws java.lang.Exception]: org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the StockRunLog.getStockRunLogListMap.
--- Check the statement (query failed).  

此时,必须要加上对应的apend才行。
情况3:
有时候,代码都是完全正确的,但是也会报错。如下:

Error getting ordinal list from JavaBean.
Cause java.lang.NumberFormatException: For input string: ""

对于这种情况,还没找到原因,根据报错信息,一直没找到错误哪里。代码都正确。无奈,重新编译了一次,倒是成功了。不过,以下内容,可以做个参考。
https://issues.apache.org/jira/browse/IBATIS-344
后续再看看此情况的原因好了。

ibatis遍历数组出错相关推荐

  1. java 数组遍历_Java中遍历数组使用foreach循环还是for循环?

    从JDK1.5起,增加了新功能Foreach,它是for循环遍历数据的一种简写形式,使用的关键字依然是for,但参数格式不同.其详细用法为: for(Type e:collection){ //对变量 ...

  2. Java中遍历数组使用foreach循环还是for循环?

    这篇文章主要介绍了Java中遍历数组使用foreach循环还是for循环?本文着重讲解for语句的语法并给出使用实例,同时总结出尽量使用foreach语句遍历数组,需要的朋友可以参考下 从JDK1.5 ...

  3. 【php基础入门】PHP环境搭建与初识php代码书写及演示PHP和JS中遍历数组的区别、引入外部文件等知识点学习笔记

    php是什么? PHP是PHP:HypertextPreprocessor(超文本预处理器)的首字母缩写,是一种跨平台的.开源的.免费的脚本语言,其语法吸收了C语言.Java 和 Perl 的特点,利 ...

  4. 页面jquery怎么循环php数组,javascript,jquery_jq遍历数组,javascript,jquery - phpStudy

    jq遍历数组 html结构如下: a: 1 2 b: 1 2 c: 1 2 d: 1 2 要求是点击btn,判断哪个类别没有选择,输出它的label 比如这个就输出"a没有选择" ...

  5. python遍历数组的同时改动数组元素

    python的for-loop的特殊性在于其更接近于「遍历」而非循环 Q:存在一个数组,对其进行遍历,符合条件的保留/删除,不符合条件的删除/保留,该如何操作? 错误示例: lst = [1, 1, ...

  6. for循环正确遍历数组

    也许有人觉得for循环遍历数组很简单啊,但是不明白for循环的原理,很容易造成严重的后果.最近有个项目,技术人员离职了,客户有个需求要修改,我就去现场帮忙改了一下,更新后第四天,客户打来电话说,系统出 ...

  7. JS中循环遍历数组的几种常用方式总结

    第一种:for循环,也是最常见的 最简单的一种,也是使用频率最高的一种,虽然性能不弱,但仍有优化空间 const arr = [11, 22, 33, 44, 55, 66, 77, 88]; for ...

  8. php 回调递归,PHP数组函数 array_walk_recursive (使用回调函数递归遍历数组元素)

    在PHP中,数组函数 array_walk_recursive () 使用回调函数递归遍历数组元素. 函数语法:array_walk_recursive ( array &$array , c ...

  9. new 数组_编程-遍历数组元素N次/填充数组至指定长度

    需求如下: 有数组 names=["a","b","c"] 需要遍历数组元素n次,比如: n=2时,期待的输出为:a,b n=5时,期待的输 ...

最新文章

  1. linux c sql server 存储过程,SQL Server 2016 - 本机编译的函数
  2. datanucleus mysql_DataNucleus Access Platform 3.1.2发布
  3. 网站访问过程理解(一点记录)
  4. 用FTP客户端实现主机和虚拟机之间文件的传输(方法1)
  5. npm i和npm i --production的区别
  6. 外地买房,提取公积金
  7. cocos2d-x游戏开发(六)自动释放池
  8. 压缩JS和CSS常用的工具
  9. 用scanline取BMP上某点的颜色,代码如下,为什么可以编译,运行时却出错呢?...
  10. jabberd2分析
  11. flink 容错机制(检查点的保存、恢复、检查点算法、保存点、状态一致性的三种级别、end-to-end exactly-once)
  12. mysql从一加到100_MYSQL用存储过程求1到100累加
  13. 60行C代码实现一个shell
  14. 简单2步轻松查找、免费下载国内外数据集?在OpenDataLab 真的可以
  15. 解决 “已有打开的与此 Command 相关联的 DataReader,必须首先将它关闭”
  16. go 语言的相对路径
  17. 使用java解析Infor XA ERP SystemLink请求响应报文
  18. 使用android.view.TouchDelegate扩大View的触摸点击区域
  19. [区块链] 密码学中Hash算法(基础)
  20. 【redis】redis各稳定版本特性(更新到6.0版本)

热门文章

  1. 第七届飞思卡尔智能车比赛的赛道边缘提取-----第一篇博客
  2. Android学习路线(十三)Activity生命周期——暂停和恢复(Pausing and Resuming )一个Activity
  3. python爬虫-爬取社区论坛房产信息-01
  4. linux与ipad屏幕共享
  5. python获取Agilent 33461A数字万用表读数
  6. java客户信息管理系统_JavaWeb客户信息管理系统.doc
  7. Conflux迎来重大升级,引入EVM兼容空间及PoS链
  8. 【React】通过jsx语法创建虚拟DOM动态及数组赋值的方法(图文+代码)
  9. Maching Learning
  10. 区分鼠标左键和右键单击