Mybatis中Dao层
public interface UsersMapper {
public void insertEntitys(List<UserEntity> users);
}
Oracle中批量插入
<insert id="insertEntitys" parameterType="list" useGeneratedKeys="false">
INSERT INTO tab_user(id,name)
select cd.* from(
<foreach collection="list" item="item" index="index" close=")" open="(" separator="union">
select
#{item.id,jdbcType=VARCHAR},
#{item.name,jdbcType=VARCHAR}
from dual
</foreach>
) cd
</insert>
Mysql中批量插入
<insert id="insertEntitys" parameterType="list">
insert into tab_user(id,name) values
<foreach collection="list"item="item" index="index"separator="," >
(
#{item.id,jdbcType=VARCHAR},
#{item.name,jdbcType=VARCHAR}
)
</foreach>
</insert>