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

数组越界,先前以为是传过去的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


            
阅读更多
上一篇servlet-api-2.4.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/s
下一篇Cause: java.lang.IllegalArgumentException: argument type mismatch
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭