MyBatis的Map中放集合对象(为了in操作等)的小提示
MyBatis是SQLMap类型的数据库访问层,使用见:ibatis 开发指南这里记录一点:为了通用性,需要Map作为Parameter Class,其中有元素filedList是一个List,即MParameter Class为Map,且Map中有集合、数组、Iterator等元素时,出现下面问题:
对于Map中取得集合对象,进行iterate时,如
<select id="findRecordsByFileIdList" parameterClass="java.util.Map" resultMap="EboxFileResultMap">
select id,file_name,parent,physical_symbol,status,type,gmt_modify,length,suffix,owner
from ebox_fs$SHARD_INDEX$
where id in <iterate open="(" close=")" conjunction=",">
#fileIdList[]#
</iterate>
and status > 0 order by type desc, file_name asc, gmt_modify desc
</select>会报错,Cause: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or property was not a Collection, Array or Iterator. 进行如下配置(红色部分):
<select id="findRecordsByFileIdList" parameterClass="java.util.Map" resultMap="EboxFileResultMap">
select id,file_name,parent,physical_symbol,status,type,gmt_modify,length,suffix,owner
from ebox_fs$SHARD_INDEX$
where id in <iterate open="(" close=")" conjunction="," property="fileIdList">
#fileIdList[]#
</iterate>
and status > 0 order by type desc, file_name asc, gmt_modify desc
</select>
页:
[1]