Here’s today’s task: the front end only gave me a date parameter with a default time:createTime: “2021-07-11 00:00:00”. What I needed to do was getting rid of the time, use the date as the search parameter to searth this date’s data.
So the mybatis can be written like this:
<if test="(createTime != null)">
and a.create_time >=DATE_FORMAT(#{createTime},'%Y-%m-%d 00:00:00')
</if>
<if test="(createTime != null)">
and a.create_time <= DATE_FORMAT(#{createTime},'%Y-%m-%d 23:59:59')
</if>
Note: the not null condition has to be like this, don’t use not null judgement for String, otherwise it will throw an exception.