mysql+mybatis一个sql里执行多条语句配置
程序员文章站
2022-07-13 16:10:35
...
在数据库连接源上加入allowMultiQueries=true,如下所示:
jdbc.jdbcUrl=jdbc:mysql://127.0.0.1:3306/databaseName?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
mybatis对应的sql文件写法:
jdbc.jdbcUrl=jdbc:mysql://127.0.0.1:3306/databaseName?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
mybatis对应的sql文件写法:
<update id="calculateAdDay" parameterType = "java.util.Date"> <!-- 先清空当天数据--> DELETE FROM ad_profit_day WHERE rpt_date=#{rptDate,jdbcType=DATE} ; <!-- 导入数据--> INSERT INTO ad_profit_day ( rpt_date,profit,self_percent,reward_price,inout_profit ) SELECT rpt_date, COALESCE(MAX(CASE WHEN menu='A' THEN profit ELSE NULL END),0) AS profit, MAX(self_percent) AS self_percent, MAX(reward_price) AS reward_price, 0 AS inout_profit FROM base_info GROUP BY rpt_date; //这里还可以继续添加sql语句,用分号结尾 </update>