Mybatis使用foreach标签出现Parameter ‘List‘ not found. Available parameters are [collection, list]的错误

Mybatis使用foreach标签出现Parameter ‘List’ not found. Available parameters are [collection, list]的错误

此作为学习时遇到的问题以及怎么解决的记录。

在mybatis中使用动态模糊查询的时候遇到的问题

mapper接口:

//这里searchContent是作为List参数,里面有多个词
public List<UserInfo> searchUserInfo(List<String> searchConten);

mapper.xml:

<select id="searchUserInfo" parameterType="List" resultMap="ArrayUserShowInfo">
	select * 
	from user_show_info 
	<where>
		userIDStatus=1 AND creatorStatus=1
			<foreach collection="List" item="item" open="AND(" close=")" separator="or">
				userName LIKE '%${item}%'
			</foreach>
	</where>
</select>

然后Mybatis报错了,Parameter ‘List’ not found. Available parameters are [collection, list]的错误

这里的解决方法是 将foreach里的collection=“List”,改为小写list
因为在参数为List时候,myabtis会自动将List参数封装成Map,map里的key就自动设置成list,所以当填入List的时候就会报错,找不到List参数,而map里的vaule就是你传入的参数。


版权声明:本文为weixin_44074090原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。