mybatis批量插入,批量更新 com.mysql.jdbc.exceptions.MySQLSyntaxErrorException

1,批量插入配置
<insert id="novel.insertBatch" parameterType="java.util.List"  useGeneratedKeys="false">
    INSERT INTO t_novel (
        `name`
    ) values
    <foreach collection="list" item="item" index="index" separator="," >
    (
        #{item.name},
    )
    </foreach>
</insert>


2,批量更新配置
<update id="novel.updateBatch" parameterType="java.util.List">
    <foreach collection="list" item="item" index="index" separator=";">
        UPDATE t_novel
        set
        updateTime=NOW()
        <if test="item.name != null">
            ,`name` = #{item.name}
        </if>
        WHERE id = #{item.id}
    </foreach>
</update>

  


3,重要,重要,重要
链接属性里面追加
allowMultiQueries=true
否则抛出com.mysql.jdbc.exceptions.MySQLSyntaxErrorException异常

原文地址:https://www.cnblogs.com/lckblog/p/7845257.html