当使用Mybatis时,有时会遇到需要根据日期进行模糊查询
前置条件:java类型Date (年月日 时分秒)
mysql类型datetime(年月日 时分秒)
传参为实体类时,即使只传年月日Date类型也会自动在后面用 0 补上时分秒,导致模糊查询失败
<if test="Time != null "> and time like concat('%', #{Time}, '%') </if>
上述语句无法查询出数据
解决方式
<if test="Time != null "> and time like concat('%', date(#{Time}), '%') </if>
使用date()对参数进行格式化