zoukankan      html  css  js  c++  java
  • springboot+Mybatis+MySql 一个update标签中执行多条update sql语句

    MySql默认是不支持这种骚操作的,但是并不代表不能实现,只需要在jdbc的配置文件中稍做配置:

    driver=com.mysql.jdbc.Driver
    url=jdbc:mysql://127.0.0.1:3306/airipo?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
    username=imp
    password=123

    其中,allowMultiQueries=true这个配置是关键,必须写

    然后在映射文件中的标签下将多条sql用;隔开即可,示例代码:

    <insert id="addUser" parameterType="User" >
          insert into t_users (name,password,phone) values (#{name}, #{password},#{phone});
          insert into t_dep (depname) values (#{depname})
     </insert>

    <update id="updateBatchSingle" parameterType="java.util.List">
    <foreach collection="list" item="item" index="index" open="" close=";" separator=";">
    update user
    <set>
    status=#{item.status}
    </set>
    where id = #{item.id}
    </foreach>
    </update>

  • 相关阅读:
    看书笔记《python基础》__1
    MQTT
    杂记
    类型转化
    soc
    时钟同步
    设置地址
    清理日志
    pandas_matplot_seaborn
    Qt_Quick开发实战精解_4
  • 原文地址:https://www.cnblogs.com/yelanggu/p/13305727.html
Copyright © 2011-2022 走看看