mybatis执行批量新增(动态)

本文介绍了如何使用MyBatis的动态SQL功能,通过foreach循环在XML映射文件中实现批量插入PrpoOrdInsuredAddr对象列表,展示了具体的接口方法和mapper文件片段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mybatis执行批量新增(动态)

interface接口

void insertPrpoOrdInsuredAddrList(@Param("prpoOrdInsuredAddrList") List<PrpoOrdInsuredAddr> prpoOrdInsuredAddrList);

xml的mapper文件

<insert id="insertPrpoOrdInsuredAddrList">
        <foreach collection="list" item="item" index="index" separator=";">
            INSERT INTO prpo_ord_insured_addr
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="item.projectId != null">project_id,</if>
                <if test="item.orderNo != null">order_no,</if>
                <if test="item.riskCode != null">risk_code,</if>
                <if test="item.insuredAddr != null">insured_addr,</if>
                <if test="item.insuredCode1 != null">insured_code1,</if>
                <if test="item.insuredCode2 != null">insured_code2,</if>
                <if test="item.insuredCode3 != null">insured_code3,</if>
                <if test="item.postCode != null">post_code,</if>
                <if test="item.createDate != null">create_date,</if>
                <if test="item.updateDate != null">update_date,</if>
                <if test="item.creatorCode != null">CREATOR_CODE,</if>
                <if test="item.updaterCode != null">UPDATER_CODE,</if>
                <if test="item.insuredCodeName1 != null">insured_code_name1,</if>
                <if test="item.insuredCodeName2 != null">insured_code_name2,</if>
                <if test="item.insuredCodeName3 != null">insured_code_name3,</if>
            </trim>

            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="item.projectId != null">#{item.projectId},</if>
                <if test="item.orderNo != null">#{item.orderNo},</if>
                <if test="item.riskCode != null">#{item.riskCode},</if>
                <if test="item.insuredAddr != null">#{item.insuredAddr},</if>
                <if test="item.insuredCode1 != null">#{item.insuredCode1},</if>
                <if test="item.insuredCode2 != null">#{item.insuredCode2},</if>
                <if test="item.insuredCode3 != null">#{item.insuredCode3},</if>
                <if test="item.postCode != null">#{item.postCode},</if>
                <if test="item.createDate != null">#{item.createDate},</if>
                <if test="item.updateDate != null">#{item.updateDate},</if>
                <if test="item.creatorCode != null">#{item.creatorCode},</if>
                <if test="item.updaterCode != null">#{item.updaterCode},</if>
                <if test="item.insuredCodeName1 != null">#{item.insuredCodeName1},</if>
                <if test="item.insuredCodeName2 != null">#{item.insuredCodeName2},</if>
                <if test="item.insuredCodeName3 != null">#{item.insuredCodeName3}</if>
            </trim>
        </foreach>
    </insert>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值