1 Écrivez des méthodes dans l'interface du mappeur
/** * 修改book表中的销量和库存 * 要使用批处理 */ Integer batchBookCountStork(@Param("bookList") List<CartItem> bookList);
<update id="batchBookCountStork" parameterType="java.util.List"> UPDATE t_book <set> <foreach collection="bookList" item="book" index="index" open="`sales` = CASE `book_id`" close="END,"> WHEN #{book.bookId} THEN sales+#{book.count} </foreach> <foreach collection="bookList" item="book" index="index" open="`stock` = CASE `book_id`" close="END,"> WHEN #{book.bookId} THEN stock-#{book.count} </foreach> </set> <where> <foreach collection="bookList" item="book" index="index" open="`book_id` IN(" close=")" separator=","> #{book.bookId} </foreach> </where> </update>
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!