ibatis遍历数组出错

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
后续再看看此情况的原因好了。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值