使用mybatis foreach标签
在serviceimpl中调用
vmmapper.insertByBatch(vmlist);
在dao中
void insertByBatch(@Param("vmInfos") List<VmInfo> vmInfos);
在xml配置文件中
<insert id="insertByBatch" parameterType="java.util.List">
insert into vm_info (wo_num, vm_name,
cpu, memery, disk,
star_time, end_time, net_num,
billing, vmstatus)
values
<foreach collection="vmInfos" item="vmInfo" separator=",">
( #{vmInfo.woNum,jdbcType=VARCHAR}, #{vmInfo.vmName,jdbcType=VARCHAR},
#{vmInfo.cpu,jdbcType=VARCHAR}, #{vmInfo.memery,jdbcType=VARCHAR}, #{vmInfo.disk,jdbcType=VARCHAR},
#{vmInfo.starTime,jdbcType=VARCHAR}, #{vmInfo.endTime,jdbcType=VARCHAR}, #{vmInfo.netNum,jdbcType=VARCHAR},
#{vmInfo.billing,jdbcType=DOUBLE}, #{vmInfo.vmstatus,jdbcType=VARCHAR})
</foreach>
</insert>
其中id字段是数据库自增的,在sql语句中去掉了id字段
可以参考:https://blog.csdn.net/m0_37981235/article/details/79131493
网友评论