在使用mybatis的时候,mapper只传了一个list集合参数,结果就报错:
Parameter 'roleIds' not found. Available parameters are [collection, list]] with root cause
就是说这个参数没有找到, 这个时候可以用@Param指定参数就行了。
mapper
import org.apache.ibatis.annotations.Param;
int deleteByIds(@Param("roleIds") List<String> roleIds);
mapper.xml
<delete id="deleteByIds" parameterType="java.util.List">
delete from role where id in
<foreach collection="roleIds" item="item" separator="," open="(" close=")" >
#{item, jdbcType=INTEGER}
</foreach>
</delete>
本文详细解析了在使用MyBatis框架时,如何正确地传递List类型参数至mapper的方法中,解决因参数未被正确识别而引发的错误。通过使用@Param注解指定参数名,确保Mapper接口和XML映射文件中的参数名一致,从而避免运行时出现参数找不到的异常。

961

被折叠的 条评论
为什么被折叠?



