使用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
