mybatis一次执行多条delete语句

来源:互联网 发布:2017网络流行词语大全 编辑:程序博客网 时间:2024/06/05 15:45

mybatis一次执行多条delete语句

  1. 首先在数据库连接URL上加上allowMultiQueries=true,默认mysql是不支持一次执行多条delete语句的。
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true

2 .在delete节点中添加多条语句:
ex:

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >    delete from music_favorite where id = #{id,jdbcType=INTEGER};    delete from music_favorite_song where f_id = #{id,jdbcType=INTEGER};  </delete>

这可以用在mybatis的级联关系删除上,删除主表记录前,先删除关联表的记录,两条一起执行

如果您觉得对您有帮助,请点个赞,谢谢!