以下 XML 是一个 MyBatis 的 update 语句示例,用于更新 t_d_nvfillformreportapply 表中的记录。

<update id="auditApply">
    update t_d_nvfillformreportapply
    <trim prefix="SET" suffixOverrides=",">
        <!-- 此处写删除处理 -->
        <if test="status != null">C_STATUS = #{status},</if>
        <if test="person != null">C_COUNAMEPERSON = #{person},</if>
        <if test="content != null">C_COUCONTENT = #{content},</if>
        C_COUAT=Date()
    </trim>
    <where>
       C_ID in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
        and (C_STATUS = 0 or C_STATUS = 4) AND C_DELETED=0
    </where>
</update>

语句分析

  • <update id="auditApply">: 定义了一个名为 'auditApply' 的 update 语句。
  • update t_d_nvfillformreportapply: 指定要更新的表。
  • <trim>: 用于去除多余的逗号,避免 SQL 语法错误。
  • <if>: 用于判断参数是否为空,只有当参数不为空时才更新对应的字段。
  • <foreach>: 用于遍历参数列表 'ids',并将每个 id 值插入到 WHERE 语句中。
  • <where>: 定义更新条件,包括 C_ID 在给定列表中,以及 C_STATUS 状态为 0 或 4 且 C_DELETED 为 0。

结论

以上 XML 代码是一个正确有效的 MyBatis update 语句,没有错误位置。

MyBatis Update 语句示例及分析

原文地址: https://www.cveoy.top/t/topic/pfqc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录