mybatis报错 Could not set parameters for mapping

求友友帮助:MyBatis中报错Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_item_1', mode=IN, javaType=class java.lang.String, jdbcType=VARCHAR, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType VARCHAR . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
代码
// dao层
    List selectMenusByCode(@Param("array") List array);
//xml文件
 SELECT t3.*, ischild
            FROM ( SELECT t1.*, IF (FIND_IN_SET(t1.MENU_CODE_P, @pids) > 0, @pids := CONCAT(@pids, ',', t1.MENU_CODE),'0') ischild
            FROM (SELECT t.* FROM t_s_bf_menu_info t ORDER BY t.ORDER_NO ) t1,
            (SELECT @pids :=
            <foreach collection="array" index="index" item="item" open="'" separator="," close="'">
                #{item,jdbcType=VARCHAR}
            foreach>
            ) t2
            ) t3
            WHERE ischild != '0'
            <if test="array != null ">
                <foreach collection="array" index="index" item="item" open=" " separator="or" close=" ">
                    menu_code =  #{item,jdbcType=VARCHAR}
                foreach>
            if>
            order by t3.order_no
运行结果及详细报错内容

Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_item_1', mode=IN, javaType=class java.lang.String, jdbcType=VARCHAR, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType VARCHAR . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).

你这个地方的分隔符少了引号。

img

修改如下,如果有用,望采纳,谢谢!

 SELECT t3.*, ischild
            FROM ( SELECT t1.*, IF (FIND_IN_SET(t1.MENU_CODE_P, @pids) > 0, @pids := CONCAT(@pids, ',', t1.MENU_CODE),'0') ischild
            FROM (SELECT t.* FROM t_s_bf_menu_info t ORDER BY t.ORDER_NO ) t1,
            (SELECT @pids :=
            <foreach collection="array" index="index" item="item" open="'" separator="','" close="'">
                #{item,jdbcType=VARCHAR}
            </foreach>
            ) t2
            ) t3
            WHERE ischild != '0'
            <if test="array != null ">
                <foreach collection="array" index="index" item="item" open=" " separator="or" close=" ">
                    menu_code =  #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
            order by t3.order_no

同意1楼看法

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^