执行以上方法报 SQL 错误的原因是在 update 语句的 <trim> 标签中,最后一行 C_COUAT=Date() 写法不正确。修正方法是使用 SET 标签包裹该语句,如下所示:

<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>
        <if test="couat != null">C_COUAT = #{couat},</if>
    </trim>
    <where>  
       C_ID in
        <foreach item="item" collection="ids" open="(" separator="," close=")">
            #{item}
        </foreach>
        and (C_STATUS = 0 or C_STATUS = 4) AND C_DELETED=0
    </where>
</update>

在修正后的代码中,添加了 if 条件判断,只有当 couat 参数不为 null 时才会更新 C_COUAT 字段。注意要将 #{couat} 替换为实际的参数名称。

MyBatis Update 语句 SQL 错误:C_COUAT=Date() 的解决方法

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

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