解决办法不外乎有三个:1、多条sql分批执行;2、存储过程或函数调用;3、sql批量执行。
MyBatis中如何一次执行多条语句(使用mysql数据库):
1、修改数据库连接参数加上allowMultiQueries=true,如:
hikariConfig.security.jdbcUrl=jdbc:mysql://xx.xx.xx:3306/xxxxx?characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true
2、直接写多条语句,用“;”隔开即可
<delete id="deleteComboInfo">
delete from amb_pairs where id in
<foreach collection="id.split(',')" close=")" open="(" separator="," item="item">
#{item}
</foreach>
; delete from amb_pair_detail where pair_id in
<foreach collection="id.split(',')" close=")" open="(" separator="," item="item">
#{item}
</foreach>
; </delete>
-END-