mybatis中使用ON DUPLICATE KEY UPDATE

starlin 1,200 2019-10-18

以前只知道在ssm框架xml中配置foreach实现批量处理数据(不存在执行insert语句,存在执行update语句),如果我想要分别给不同的记录插入不同的值怎么办,那么可以通过VALUES修改,特此记录下:

    <insert id="editformDataFlows">
        insert into formdataflow (id,flowname, nodename, approvalrelation, prenodename, approvalperson, approvalpersonname,                       approvalcondition, approvalconditionzh, nodecontent, inputdate)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.id},#{item.flowName},#{item.nodeName},#{item.approvalRelation},#{item.preNodeName},#{item.approvalPerson},#{item.approvalPersonName},#{item.approvalCondition},#{item.approvalConditionZH}
            ,#{item.nodeContent},NOW())
        </foreach>
        ON DUPLICATE KEY UPDATE
        id = values(id),
        flowName = values(flowName),
        nodename = values(nodeName),
        prenodename = values(preNodeName),
        approvalrelation = values(approvalRelation),
        approvalperson = values(approvalPerson),
        approvalpersonname = values(approvalPersonName),
        approvalcondition = values(approvalCondition),
        approvalconditionzh = values(approvalConditionZH),
        nodecontent = values(nodeContent)
    </insert>

end,感谢阅读!


# Mybatis