<update id="updateStatus" parameterType="com.itframe.beans.GenericBean">
    update task_info_b
    <trim prefix="set" suffixOverrides=",">
        <if test="status!=null and status!=''">
            `status`= #{status},
        </if>
        <if test="status!=null and status!='' and status = 2">
            timeInfoStartTime = now(),
        </if>
    </trim>
    where id = #{taskId}
</update>

此sql的bug在于我想在status参数为2的时候,执行更新 timeInfoStartTime开始时间字段,可并无如愿

在cntroller或者service层打断点拦截下参数看了下类型,status参数是String类型,初步判断是<if>判断没过去

mybatis执行update时标签来判断字符串相等问题

初步怀疑是  status = 2 这个对字符串的判断有误,于是百度一番,了解到字符串在mybatis中比较的方法是;:;

a.            <test="sex=='Y'.toString()">

b.            <test = 'sex== "Y"'>

于是将sql改成;;;程序就会按照你想要的样子执行

<update id="updateStatus" parameterType="com.itframe.beans.GenericBean">
    update task_info_b
    <trim prefix="set" suffixOverrides=",">
        <if test="status!=null and status!=''">
            `status`= #{status},
        </if>
        <if test="status == '2'.toString()">
            timeInfoStartTime = now(),
        </if>
        <if test="status == '1'.toString()">
            timeInfoStartTime = null
        </if>
    </trim>
    where id = #{taskId}
</update>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2022-02-07
  • 2022-02-07
相关资源
相似解决方案