昨天在使用:
<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>