在mybatis同一個方法中執行多個SQL語句實現方法
阿新 • • 發佈:2018-12-15
一、oracle資料
<delete id="delete" parameterType="upc.cbs.HtxxlrEntity">
begin
delete from PC_CBS_CONTRACT where contract_id = #{contract_id};
delete from PC_CBS_UPLOAD_FILES where contract_id = #{contract_id} and filetype='合同附件';
delete from PC_CBS_CONTRACT_TEAM where contract_id = #{contract_id};
end;
</delete>
只需要新增begin 和 end; 每個sql語句用“;”結束
二、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="delete" parameterType="upc.cbs.HtxxlrEntity"> delete from PC_CBS_CONTRACT where contract_id = #{contract_id}; delete from PC_CBS_UPLOAD_FILES where contract_id = #{contract_id} and filetype='合同附件'; delete from PC_CBS_CONTRACT_TEAM where contract_id = #{contract_id}; </delete>
mysql需要修改資料連線新增allowMultiQueries=true屬性;每個sql語句用“;”分開