關於 mybatis 報invalid comparison: java.util.Arrays$ArrayList and java.lang.String異常

這是一個根據list集合的查找數據的 sql,在接收list的時候加了判斷 list != ‘ ’ “”,引起了集合與Stirng類型的比較,故報錯

 

<if test="list != null and list != '' ">
     AND roo_id IN
    <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
       #{id}
    </foreach>
</if>

複製代碼

 

解決方案:   將判斷條件改爲 : list.size >0

複製代碼

<if test="list != null and list.size > 0 ">
     AND roo_id IN
    <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
       #{id}
    </foreach>
</if>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章