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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM