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("") 里面的值

 


免責聲明!

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



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