springBoot + mybatis实现执行多条sql语句出错解决方法

在Idea中执行多条sql语句的修改(mybatis默认的是执行sql语句是执行单条,所以要执行多条的时候需要进行配置)

需要在连接字符串中添加上&allowMultiQueries=true,例如:

spring.datasource.url=jdbc:mysql://localhost:3306/plantform?characterEncoding=utf8&useSSL=true&allowMultiQueries=true
不添加这个的时候执行会出错
执行多条修改的方法(.xml配置)
<update id="UpdateList">
            <foreach collection="list" item="item" separator=";">
                    UPDATE 表名
                    set 列名1=#{item.列名1数据对应实体字段},
                    列名2=#{item.列名2数据对应实体字段}
                    where phone=#{item.查询条件}
            </foreach>
</update>
UpdateList

这种写法,在Dao层可以直接传入参数void UpdateList(List<实体> list);

这样就能识别,虽然是多个update,但是是一次执行的

原文地址:https://www.cnblogs.com/myyBlog/p/8794151.html