1 .
<update id="updateStatus" parameterMap="SystemUserNotice">
UPDATE
<include refid="table" />
SET
`status` = #{status},`edit_time`=#{editTime}
WHERE
`id`
IN
(
<foreach collection="idList" item="item" index="index" separator=",">
#{item}
</foreach>
)
</update>
2.
public class UserMessage{
private Long id;
private MessageModeEnum mode;
private UserMessageTypeEnum sendType;
private String title;
private String content;
private List<Long> userIds;
private String iconUrl;
private String args;
private LocalDateTime createTime;
private LocalDateTime readTime;
<insert id="userMessage" parameterMap="UserMessage">
INSERT INTO
<include refid="table" />
(`mode`,`send_type`,`title`,`content`,`user_id`,`icon_url`,`args`,`create_time`)
VALUES
<foreach collection="userIds" item="userId" index="index" separator =",">
(#{mode},#{sendType},#{title}, #{content}, #{userId}, #{iconUrl}, #{args},#{createTime})
</foreach >
</insert>
3.
<insert id="createList" parameterType="java.util.List">
INSERT INTO
<include refid="table" />
(`xxxx_id`, `xxx_id`)
VALUES
<foreach collection="list" item="o" index="index" separator =",">
(#{o.xxxx_id}, #{o.xxx_id})
</foreach >
</insert>
本文介绍使用MyBatis进行批量数据更新和插入的方法,包括通过foreach元素处理多个ID的更新操作,以及如何一次性插入多条记录到数据库中。探讨了参数映射和集合的使用,适用于需要高效数据库操作的场景。
7120

被折叠的 条评论
为什么被折叠?



