您的位置:首页 > 编程语言 > Java开发

Parameter 'xxxx' not found. Available parameters are [list] at java.util.concurrent.FutureTask

2016-04-07 16:07 776 查看
Parameter 'categoryIds' not found. Available parameters are [list] at java.util.concurrent.FutureTask.report(FutureTask.java:122);

xml配置

<select id="getContainInfoByListCategoryIds" resultType="CmsCategoryContainInfoSource">

SELECT
containsInfo.* from cms_category_containinfo containsInfo where containsInfo.categoryid in

<foreach collection="categoryIds" index="index" item="id" open="(" separator="," close=")">

#{id}

</foreach>

</select>

对比了一下发现categoryIds在dao中也是这个名字,而且这个参数确实是list,查询下mybatis文档http://www.mybatis.org/mybatis-3/zh/dynamic-sql.html#foreach有如下说明:


foreach

动态 SQL 的另外一个常用的必要操作是需要对一个集合进行遍历,通常是在构建 IN 条件语句的时候。比如:

<select id="selectPostIn" resultType="domain.blog.Post">
SELECT *
FROM POST P
WHERE ID in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>


foreach 元素的功能是非常强大的,它允许你指定一个集合,声明可以用在元素体内的集合项和索引变量。它也允许你指定开闭匹配的字符串以及在迭代中间放置分隔符。这个元素是很智能的,因此它不会偶然地附加多余的分隔符。

注意 You can pass
any Iterable object (for example List, Set, etc.), as well as any Map or Array object to foreach as collection parameter. When using an Iterable or Array, index will be the number of current iteration and value item will be the element retrieved in this iteration.
When using a Map (or Collection of Map.Entry objects), index will be the key object and item will be the value object.

注意翻译一下的意思是:你可以传递一个 List 实例或者数组作为参数对象传给 MyBatis。当你这么做的时 候,MyBatis 会自动将它包装在一个 Map 中,用名称在作为键。List 实例将会以“list” 作为键,而数组实例将会以“array”作为键;所以解决办法有两种,第一在配置文件中的item改为list;第二在dao中将参数放入map中,key值任意即可。
Map<String,List> map=new HashMap();

map.put("categoryIds", categoryIds);

return getSqlSession().selectList("CmsCategoryContainInfoSource.getContainInfoByListCategoryIds", map);

解决办法参考:http://chenzhou123520.iteye.com/blog/1921284
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: