您的位置:首页 > 运维架构

Mybatis使用<foreach collection="***" item="**" open="(" separator="," close=")">问题

2016-06-02 09:54 513 查看
昨天在使用:

<foreach collection="userTypes" item="userType" open="(" separator="," close=")">

时出现一个错误,提示SQL错误,检查发现是在“<foreach>”前面的<if></if>判断语句中使用非空字符串判断,而item只接受list,数组和map,所以出错!
<if test="userTypes != null">
AND USERTYPE in
<foreach collection="userTypes" item="userType" open="(" separator="," close=")">
#{userType}
</foreach>
</if>

原始是:
<if test="userTypes != null and '' != userTypes ">
AND USERTYPE in
<foreach collection="userTypes" item="userType" open="(" separator="," close=")">
#{userType}
</foreach>
</if>


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: