问题描述
<select id="getByTypeIDs" resultMap="result"> SELECT DET_NAME FROM TYPE_DEATAIL <dynamic prepend="where"> <iterate property="detTypeId" open="(" close=")" conjunction="or"> DET_TYPE_ID=#detTypeId[]# </iterate> </dynamic> </select>public List getByTypeIDs(int detTypeId[])throws SQLException{return sqlMapper.queryForList("getByTypeIDs",detTypeId);} 2008-08-08 14:55:40,937 DEBUG [java.sql.Connection] - {conn-100000} Connection2008-08-08 14:55:40,937 DEBUG [com.ibatis.common.jdbc.SimpleDataSource] - Returned connection 1623405 to pool.at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:156)... 7 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)... 15 more
解决方案
使用的是默认参数 记不太清怎么用了用<select id="getByTypeIDs" resultMap="result"> SELECT DET_NAME FROM TYPE_DEATAIL <dynamic prepend="where"> <iterate property="value" open="(" close=")" conjunction="or"> DET_TYPE_ID=#value[]# </iterate> </dynamic> </select> 或<select id="getByTypeIDs" resultMap="result"> SELECT DET_NAME FROM TYPE_DEATAIL <dynamic prepend="where"> <iterate property="" open="(" close=")" conjunction="or"> DET_TYPE_ID=#value[]# </iterate> </dynamic> </select> 试试
解决方案二:
你的detTypeId 肯定是传了一个空进去, 或者是空的数组进去.你要先判断是 isNotNull, 再判断isNotEmpty, 再使用iterator