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

 

posted @ 2019-05-17 12:44  三号小玩家  阅读(10234)  评论(1编辑  收藏  举报
Title
三号小玩家的 Mail: 17612457115@163.com, 联系QQ: 1359720840 微信: QQ1359720840