xml批量插入消息:
keyProperty ,默认值unset,用于设置getGeneratedKeys方法或selectKey子元素返回值将赋值到领域模型的哪个属性中
resultType ,keyPropety所指向的属性类全限定类名或类型别名
order属性 ,取值范围BEFORE|AFTER,指定是在insert语句前还是后执行selectKey操作
statementType ,取值范围STATEMENT,PREPARED(默认值),CALLABLE
1.传参
<insert id="insertIdIn" parameterType="java.util.List">
<selectKey resultType="long" keyProperty="id" order="AFTER">
SELECT
LAST_INSERT_ID()
</selectKey>
insert into notification (user_id, notification_name)
values
<foreach collection="idList" item="userId" index="index" separator=",">
( #{userId}, "XXXX")
</foreach>
</insert>
2.别的表中的数据
INSERT INTO TStudent(name,age)
<foreach collection="list" item="item" index="index" open="(" close=")" separator="union all">
SELECT #{item.name} as a, #{item.age} as b FROM DUAL
</foreach>
本文介绍如何使用XML配置文件实现批量插入操作,重点讲解了MyBatis框架中的<selectKey>元素和<insert>元素的用法,包括参数传递、selectKey元素的属性设置以及foreach循环的应用。
2212

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



