目的:要根据分类的ID数组列表获得属于这些分类的News对象数组。
函数调用为newslist=(ArrayList)sqlMap.queryForList("getNewsByCatalogList", catalogList);
一开始直接用string的写法
xml 代码
SELECT
newsId as newsId,
title as title,
content as content,
topicId as topicId
FROM cnsv_news where cnsv_news.catalogId IN(#catalogListStr
catalogListStr为String类型,值为"1,2,3"的样子
发现有问题,只能得到第一个ID的对象,显然不行。
后来按照ibatis的说明文档,使用iterate写配置文件:
xml 代码
SELECT
newsId as newsId,
title as title,
content as content,
topicId as topicId
FROM cnsv_news wherecnsv_news.catalogId=#catalogList[]#
一直没调试成功,出现com.ibatis.common.beans.ProbeException: Error getting ordinal list from JavaBean错误。查资料、网上搜了一通都解决不了,后来看了一下JPetStore-5.0的例子结合我跟它的区别和Error getting ordinal list from JavaBean,感觉可能是我的resultClass—News里面没有catalogList属性引起的,后来也证实猜测是正确的。我的News里面显然不适合有catalogList属性,一时想不到办法,抱着必将失败的心态干脆把property=”catalogList”删除掉试试(ibatis说明文档上说property是必选的,这句话可真是误人子弟啊),删除之后一运行竟然成功了。
删除之后:
SELECT
newsId as newsId,
title as title,
content as content,
topicId as topicId
FROM cnsv_news where
cnsv_news.catalogId=#catalogList[]#
原因分析:有了property=”catalogList”这句ibatis会在News里面找catalogList,而News里面有没有这个属性所以就抛出com.ibatis.common.beans.ProbeException: Error getting ordinal list from JavaBean异常。删掉property=”catalogList”之后,ibatis就会在传入的parameterClass中找catalogList,这正是我需要的。
Java架构俱乐部,QQ群2826942 ,交流Java架构,领域模型,设计模式,AOP,IOC,轻量级,DDD,项目管理,设计思想等问题,聚集经验丰富的高级程序员,架构师,项目经理等交流以上层面较高的问题。欢迎各位有识之士加入,共同探讨、发表高见、广结精英。为了使各位成员免受无聊信息和低端问题的打扰,请尽量避免讨论代码实现等入门级问题,维护本群的氛围和讨论质量。新手勿加