Mybatis的xml循环List<String>

<if test="stringList != null and stringList .size() > 0 ">
    AND t.code in
    <foreach collection="stringList " item="item" open="(" separator="," close=")"     index="index">
        '${item}'
    </foreach>
</if>

注意:

        1:不能用#,要用$

        2:${item}要用引号 ' '

错误示范:

        1:如果不用$,用# 例如 '#{item}' 会报如下错误:

         Parameter index out of range (1 > number of parameters, which is 0).

        2:如果不用 ' ' 例如 ${item} 会报错:

        java.sql.SQLSyntaxErrorException: Unknown column 'H261265' in 'where clause'

 3:如果即不用$,也不用 ' ' 例如 #{item}  ,会报如下错误:

 There is no getter for property named '__frch_item_0' in 'class xxxx'


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