mybatis 批量新增和修改

<insert id="addAttrValueBatch">
    <if test="materialCustomerAttrPOS != null and materialCustomerAttrPOS.size>0">
        insert into
        material_customer_attr(core_id,attr_code,attr_value,create_time,create_user,update_time,update_user)
        values
        <foreach collection="materialCustomerAttrPOS" item="it" separator=",">
            (#{it.coreId},#{it.attrCode},#{it.attrValue},now(),#{userId},now(),#{userId})
        </foreach>
    </if>
</insert>

<update id="updateBatch">
    <foreach collection="coreAttrlist" item="bean" index="index" open="" close="" separator=";">
        UPDATE material_core_attr
        <set>
            name = #{bean.name},
            attach_file_ids = #{bean.attachFileIds},
            release_time = #{bean.releaseTime},
            update_time = now(),
            update_user = #{userId}
        </set>
        <where>
            id = #{bean.id}
        </where>
    </foreach>
</update>

 

posted @ 2021-11-15 11:08  Bob.Xie  阅读(223)  评论(0编辑  收藏  举报