方式一: 在数据表有主键或唯一键时批量插入或修改数据
<insert id="saveOrUpdateBatch">
<foreach collection="list" index="index" item="item" open="" separator="" close="">
insert into t_data(pdate, periodid, zcqdl, zcqdj, loguser, logtime) values (
#{item.pdate}, #{item.periodid}, #{item.power}, #{item.price}, #{item.loguser}, sysdate()
) on duplicate key update
zcqdl = values(zcqdl),
zcqdj = values(zcqdj),
loguser = values(loguser),
logtime = values(logtime);
</foreach>
</insert>
方式二:
<insert id="insertScreenMonthEnergy">
INSERT INTO t_month
(month,jqyc)
VALUES
<if test="insertList !=null">
<foreach collection="insertList" index="index" item="item" open="(" separator="),(" close=")">
#{item.month},#{item.jqyc}
</foreach>
</if>
</insert>