mybatis判断集合长度

使用mybatis框架在写sql的时候碰到一个异常:

 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

  类似于sql这样出现的异常

SELECT * FROM eval_question  WHERE   id not in()

  后来就查询前先判断前台传入集合如果长度小于0就不走下面的操作。就不会异常了。

 <select id="NotInByEvalQuestion" resultType="com.rm.eval.entity.EvalQnQuestion">
        SELECT * FROM eval_question  WHERE  1=1
        <if test="null != strlist and strlist.size > 0">
          and  id not in
            <foreach collection="strlist" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>

  相当于

SELECT * FROM eval_question  WHERE   id not in("")或者
SELECT * FROM eval_question  WHERE  1=1
原文地址:https://www.cnblogs.com/q1359720840/p/10880708.html