一、mysql中的批量修改语句怎么写
表结构
CREATE TABLE `blog` (
`bid` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`author_id` int(11) DEFAULT NULL,
PRIMARY KEY (`bid`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
sql语句
update blog
set name =
CASE bid
WHEN 1 THEN
"RabbitMQ延时消息+修改"
WHEN 2 THEN
"MyBatis源码分析+修改"
END,
author_id =
CASE bid
WHEN 1 THEN
100
WHEN 2 THEN
200
END
二、java中的mapper.xml代码
<update id="updateBlogList">
update blog set
name =
<foreach collection="list" item="blogs" index="index" separator=" " open="case bid" close="end">
when #{blogs.bid} then #{blogs.name}
</foreach>
,author_id =
<foreach collection="list" item="blogs" index="index" separator=" " open="case bid" close="end">
when #{blogs.bid} then #{blogs.authorId}
</foreach>
where bid in
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item.bid,jdbcType=INTEGER}
</foreach>
</update>