【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 tb_work
        
            start_time = #{startTime},
            end_time = #{endTime},
            status = #{status},
        
        where employee_id = #{employee.employeeId} and work_time = #{workTime}
    

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

Mark

你可能感兴趣的:(【Mybatis】Mybatis使用日期类型参数作为where查询条件遇到的一点小坑)