【Mybatis】Mybatis使用日期类型参数作为where查询条件遇到的一点小坑

@Data
public class Work {
    private Employee employee;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date workTime;
    private Date startTime;
    private Date endTime;
    private Integer status;
}

在写修改Work表里的status条件语句的时候,因为这张表中employeeId和workTime均为主键,所以需要将date类型参数作为查询条件。

<update id="updateWorkTime" parameterType="com.alone.hotel.entity.Work" >
        update tb_work
        <set>
            <if test="startTime != null ">start_time = #{startTime},</if>
            <if test="endTime != null ">end_time = #{endTime},</if>
            <if test="status != null ">status = #{status},</if>
        </set>
        where employee_id = #{employee.employeeId} and work_time = #{workTime}
    </update>

写出上面的语句之后发现影响行数始终为0,修改未成功。
查了一晚上发现,需要将where条件修改为:
where employee_id = #{employee.employeeId} and work_time = date(#{workTime})
mybatis接收参数也挺特殊的,一般格式为:#{param,jdbcType=VARCHAR}

Mark

猜你喜欢

转载自blog.csdn.net/qq_41279172/article/details/105000946