<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>判断没过去
初步怀疑是 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>