我正在尝试使用 <foreach> 但遇到一些问题。代码如下:
Bean.java
private class Bean{
private String clientId;
//getter and setter
}
道.xml
<mapper namespace="...Dao">
<resultMap id="bean" type="...Bean">
<result property="clientId" column="CLIENT_ID" />
</resultMap>
<select id="getData" resultMap="bean"
parameterType="someBean">
SELECT *
FROM tableClient
WHERE CLIENT_ID IN
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
trim(#{clientId})
</foreach>
</select>
</mapper>
该查询打算在以下位置返回数据:
List<Bean> getData(List<Bean> bean);
虽然查询执行成功,但是在绑定数据时引发异常。 Stacktrace :
2013-03-23 15:11:13,637 DEBUG [getData] ==> Preparing: SELECT * FROM tableClient WHERE CLIENT_ID IN ( trim(?) , trim(?) , trim(?) )
2013-03-23 15:11:13,637 DEBUG [SqlSessionUtils] Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@117c0eb]
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'clientId' not found. Available parameters are [list]
2013-03-23 15:11:13,637 DEBUG [DataSourceUtils] Returning JDBC Connection to DataSource
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)
at $Proxy11.selectList(Unknown Source
....