list from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index out of range: -1

原创 2012年03月26日 12:59:31
数组越界,先前以为是传过去的list参数为null或者list.size==0,于是就在执行ibatis语句前添加了判断 。代码如下
if (ids != null&&0 < ids.size()) {
			List<XiuCentAttr> xiuCentAttrList = sqlMapClient
					.queryForList(
							"XIU_CENT_ATTR.ibatorgenerated_selectXiuCentAttrListByItemIdList",
							ids);
			for (XiuCentAttr xiuCentAttr : xiuCentAttrList) {

ibatis代码如下:
<select id="ibatorgenerated_selectXiuCentAttrListByItemIdList" resultMap="ibatorgenerated_BaseResultMap"
		parameterClass="java.util.List">
		<!-- WARNING - This element is automatically generated by Apache iBATIS 
			ibator, do not modify. This element was generated on Thu Mar 15 15:18:21 
			CST 2012. -->
		select
		<include refid="ibatorgenerated_column_name" />
		from XIU_CENT_ATTR
		where ITEM_ID 
		<iterate prepend="in" property="ids" conjunction="," open="(" close=")">
			#ids[]#
      </iterate>
</select>

始终找不到问题
即多了一个property,这个时候ibatis会从参数中寻找属性为ids的对象,而list是一个对象没有属性就会报

异常,解决方法就是去掉property="ids"

其实这种写法是相对第二种以map为参数而言的,你可以使用map传入参数设置属性为 property对应名即可




--- The error occurred in com/pltfm/index/sqlmap/XIU_CENT_ATTR_SqlMap.xml. --- The error occurred while preparing the mapped statement for execution. --- Check the XIU_CENT_ATTR.ibatorgenerated_selectXiuCentAttrListByItemIdList. --- Check the parameter map. --- Cause: com.ibatis.common.beans.ProbeException: Error getting ordinal list from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index out of range: -1at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:204)at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:94)at com.pltfm.index.dao.XiuCentAttrDAOImpl.selectXiuCentAttrListByItemIdList(XiuCentAttrDAOImpl.java:205)at com.pltfm.index.service.XiuCentAttrServer.selectXiuCentAttrListByItemIdList(XiuCentAttrServer.java:24)at com.pltm.index.service.XiuCentAttrServerTest.testSelectXiuCentAttrListByItemIdList(XiuCentAttrServerTest.java:52)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)at java.lang.reflect.Method.invoke(Unknown Source)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)at org.junit.runners.ParentRunner.run(ParentRunner.java:236)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)Caused by: com.ibatis.common.beans.ProbeException: Error getting ordinal list from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index out of range: -1at com.ibatis.common.beans.BaseProbe.getIndexedProperty(BaseProbe.java:86)at com.ibatis.common.beans.GenericProbe.getObject(GenericProbe.java:54)at com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements.IterateTagHandler.doStartFragment(IterateTagHandler.java:47)at com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.processBodyChildren(DynamicSql.java:156)at com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.processBodyChildren(DynamicSql.java:98)at com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.process(DynamicSql.java:78)at com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.getParameterMap(DynamicSql.java:60)at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:172)... 32 moreCaused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1at java.lang.String.substring(Unknown Source)at com.ibatis.common.beans.BaseProbe.getIndexedProperty(BaseProbe.java:50)... 39 more


                    

相关文章推荐

ibatis传入list对象

在使用ibatis的时候经常需要传入list对象,sql语句如下。 #list[]# 这个是简单的sql语句,对于list中是别的对象的,比如List这个参数传进来时需要这样...

Ibaitis Caused by: com.ibatis.common.beans.ProbeException: Error getting ordinal list from JavaBean.

由于业务代码需要,用iterate来遍历整个数组,来批量查询,sqlMap如下 select id,name from yw_tag where 1=1 a...

在ibatis中使用Dynamic SQL时property属性的用法

--- Cause: com.ibatis.common.beans.ProbeException: Error getting ordinal list from JavaBean. Cause j...
  • lywybo
  • lywybo
  • 2013年06月13日 18:47
  • 3194

【解决问题.思路篇】StringIndexOutOfBoundsException:String index out of range: -1

看到题目,就应该能想到应该是字符串过长引起的问题。下面咱们分析一下。 报错: 严重: Servlet.service()for servlet jsp threw exception java.l...

mvn install:java.lang.StringIndexOutOfBoundsException: String index out of range: -1问题的解决

出错信息:  [INFO] [INFO] --- maven-bundle-plugin:1.0.0:bundle (default-bundle) @ monitorbundle --- ja...

spark将数据保存到elasticsearch,老是爆java.lang.StringIndexOutOfBoundsException: String index out of range: -1

spark将数据保存到elasticsearch,老是爆java.lang.StringIndexOutOfBoundsException: String index out of range: -1...
  • sikers
  • sikers
  • 2016年02月18日 18:31
  • 2181

Hibernate query.list()查询发生java.lang.StringIndexOutOfBoundsException: String index out of range: 0错误

使用Hibernate的query查询数据时发生以下错误 java.lang.StringIndexOutOfBoundsException: String index out of range: ...
  • lxm_bey
  • lxm_bey
  • 2014年09月05日 14:37
  • 2320

eclipse Java文件打开异常解决方法 :java.lang.StringIndexOutOfBoundsException: String index out of range: 26

,eclipse里Java文件没有报错,却打不开了。 经过一番探索,终于发现了原因。至于在eclipse里打开这个文件,有两种方法。...

关于ibatis的parameter index out of range (1 > number parameters which is 0).异常

说起来这个异常很坑爹啊,调试了一下午,数据一点都

String index out of range: -1

      前两天报字符串越界,查找中发现,应该是取某一个字符的位置时,出错了,原来使用lastIndexOf时要取得这个字符在被查找的字符串里没有。解决方法,在取位置之前,先要验证一下,字符是否存在...
  • zoucui
  • zoucui
  • 2006年08月18日 14:10
  • 38432
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:list from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index out of range: -1
举报原因:
原因补充:

(最多只允许输入30个字)