Mybatis 循环 foreach, 批量操作

 

 

 

mapper.java: 

   int modifySortOfGoods(@Param("idlist") List<String> goodsIds, @Param("goodsSortId")Long goodsSortId);

 

mapper.xml

<update id="modifySortOfGoods" parameterType="java.util.List">
   UPDATE goods SET goods_sort_id = #{goodsSortId}
   WHERE id in
    <foreach item="goodsId" collection="idlist" separator="," open="(" close=")" index="">
        #{goodsId}
    </foreach>
</update>

 

result:

UPDATE goods SET goods_sort_id = 4
 WHERE id in ( '1' , '2' );

 

 

foreanch 标签中的 collection的值要对应mapper.java中的@param("") 里面的值

 

posted @ 2019-05-22 15:56  _戈多  阅读(2648)  评论(0编辑  收藏  举报