MyBatis中<foreach>的使用

     <delete id="deleteBatchCollectionById">
          delete from t_collection
          <where>
               uid=#{uid} and vid in
              <foreach collection="vidArray" open="(" separator="," close=")" item="vid" >
                   #{vid}
              </foreach>
          </where>

     </delete>

注:

    <where>標籤就相當於where
    collection:存放集合的參數值,不需要加入#{}
    open:拼接的sql代碼以什麼開頭,可以加入其他元素,比如open="vid in (",體現了mybatis的靈活性
    close:拼接的sql代碼以什麼結尾
    item:從collection中取出的每一個條目
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章