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这个参数传进来时需要这样...
  • yizhizouxiaqu
  • yizhizouxiaqu
  • 2012年12月08日 19:51
  • 9340

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...
  • qq_16681169
  • qq_16681169
  • 2016年07月22日 08:48
  • 2849

ProbeException: Error getting ordinal list from JavaBean. Cause java.lang.StringIndexOutOfBoundsExce

Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:    --- The error occurred in sqlmap...
  • u010002184
  • u010002184
  • 2018年01月08日 17:33
  • 54

mybatis generator StringIndexOutOfBoundsException异常

在使用 mybatis generator 生成代码的时候,如果出现 java.lang.StringIndexOutOfBoundsException: String index out of...
  • zk_spring
  • zk_spring
  • 2016年04月06日 18:13
  • 1339

ibatis批量插入对象

正确写法: dao public Map saveWxcircleList_one(List wdto){ Map map = new HashMap(); List ...
  • dandanforgetlove
  • dandanforgetlove
  • 2015年11月17日 16:54
  • 3980

ibatis的Iterate元素的用法。

转自:http://hongzhguan.iteye.com/blog/1222353       property="" /*可选,           ...
  • suyu_yuan
  • suyu_yuan
  • 2016年09月28日 10:30
  • 558

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
  • 2677

Caused by: java.lang.StringIndexOutOfBoundsException: length=5; regionStart=0; regionLength=-1

Caused by: java.lang.StringIndexOutOfBoundsException: length=5; regionStart=0; regionLength=-1 原因:在...
  • Ansionnal
  • Ansionnal
  • 2013年04月25日 11:27
  • 16817

关于StringIndexOutOfBoundsException那些事~

今天做截取字符串操作时遇到了这样的问题: 10-12 10:51:54.654: E/AndroidRuntime(31917): Caused by: java.lang.StringIndexO...
  • Bobbybear
  • Bobbybear
  • 2013年10月12日 11:30
  • 12434

在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
  • 3492
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:list from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index out of range: -1
举报原因:
原因补充:

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