zoukankan      html  css  js  c++  java
  • 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,但是是一次执行的

  • 相关阅读:
    jQuery对select操作
    左眼跳跳 100万
    [推荐] 世界上最健康的作息时间表
    放弃了mapbar 选用google map
    记录
    WPF等待窗口
    PL界面
    C# 获得随机数
    组合
    delphi版淘小宝图片下载工具
  • 原文地址:https://www.cnblogs.com/myyBlog/p/8794151.html
Copyright © 2011-2022 走看看