MySql默认是不支持这种骚操作的,但是并不代表不能实现,只需要在jdbc的配置文件中稍做配置:
配置文件:jdbc.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/pam\u003fuseUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&serverTimezone=PRC&useSSL=false&tinyInt1isBit=false
name=xxxx
password=123456
其中,allowMultiQueries=true这个配置是关键,必须写
然后在映射文件中的标签下将多条sql用(;)分隔;
“allowMultiQueries=true”的作用:
1.可以在sql语句后携带分号,实现多语句执行。
2.可以执行批处理,同时发出多个SQL语句。
<update id="update" parameterType="map">
delete from t_receipt_detail where mid=#{cm.receiptID};
delete from t_receipt where id=#{cm.receiptID};
update t_invoicepaydetail
set receiptid=null,editby=#{cm.userId},editon=now()
where receiptid=#{cm.receiptID}
</update>