mybatis 批量插入

<insert id="insertBatch">
    INSERT INTO t_user
            (id, name, sex)
    VALUES
    <foreach collection ="list" item="user" separator =",">
         (#{user.id}, #{user.name}, #{user.sex})
    </foreach >
</insert>

特别注意:mysql默认接受sql的大小是1048576(1M),即第三种方式若数据量超过1M会报如下异常:(可通过调整MySQL安装目录下的my.ini文件中[mysqld]段的"max_allowed_packet = 1M")

 

nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (5677854 > 1048576).

You can change this value on the server by setting the max_allowed_packet' variable.

 

posted @ 2020-11-18 11:15  晓燚缺  阅读(56)  评论(0编辑  收藏  举报