mybatis 批量新增,如果列表里面有id那么则更新,mysql数据库
<insert id="batchAdd" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
insert into t_schedule(
id,
doctorId,
deptId,
`type`,
`date`,
`desc`,
startTime,
endTime,
`number`)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.id},
#{item.doctorId},
#{item.deptId},
#{item.type},
#{item.date},
#{item.desc},
#{item.startTime},
#{item.endTime},
#{item.number}
)
</foreach>
ON DUPLICATE KEY UPDATE
doctorId=VALUES(doctorId),
deptId=VALUES(deptId),
`type`=VALUES(`type`),
`date`=VALUES(`date`),
`desc`=VALUES(`desc`),
startTime=VALUES(startTime),
endTime=VALUES(endTime),
`number`=VALUES(`number`)
</insert>
VALUES里面取的是sql的字段,如果是关键字,注意要加上``