mybatis 批量插入oracle

来源:互联网 发布:甘肃干部网络考试答案 编辑:程序博客网 时间:2024/05/17 02:45

mybatis 批量插入oracle

使用如下语句

<insert id="addShortMessage" parameterType="list" useGeneratedKeys="false">
  INSERT INTO dm_short_message_tb(ID,NAME,PHONE,CONTENT,CONTENT_TYPE,STATUS)
    select cd.* from(
    <foreach collection="list" item="item" index="index"  close=")" open="(" separator="union">
        select
       #{item.id,jdbcType=VARCHAR},#{item.name,jdbcType=VARCHAR},
       #{item.phone,jdbcType=VARCHAR},#{item.content,jdbcType=VARCHAR},
       #{item.contentType,jdbcType=VARCHAR},#{item.status,jdbcType=VARCHAR}
        from dual
    </foreach>
    ) cd
</insert>

网上的大部分错误由于 没有指定useGeneratedKeys="false"

dao层代码格式如下

public interface SendMessageDao {

    public void addShortMessage(List<ShortMessage> listMessage);
}


mybatis 批量插入mysql 如下

<insert id="addShortMessage" parameterType="list">  
    insert into dm_short_message_tb(ID,NAME,PHONE,CONTENT,CONTENT_TYPE,STATUS)  
    values  
    <foreach collection="list"item="obj" index="index"separator="," >  
       (#{item.id,jdbcType=VARCHAR},#{item.name,jdbcType=VARCHAR},
       #{item.phone,jdbcType=VARCHAR},#{item.content,jdbcType=VARCHAR},
       #{item.contentType,jdbcType=VARCHAR},#{item.status,jdbcType=VARCHAR})  
    </foreach>  
</insert>


原创粉丝点击