springboot + Mybatis + MySql update a tag execute multiple update sql statement

Mysql does not support this operation show, but does not mean and can not be achieved, require only a slight modification to do something on the line in the configuration file 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

Which, allowMultiQueries = true this configuration is the key, you must write

Then the map file sql with a plurality of labels; can be separated, the sample code:

<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>

 

Guess you like

Origin www.cnblogs.com/qingmuchuanqi48/p/10934965.html