mybatis框架支持直接用>=或<=查询日期范围,如:
<if test="startTime != null and startTime != ''">
and timer.create_time >= #{startTime}
<if test="endTime != null and endTime != ''">
and timer.create_time <= #{endTime}
</if>
但这种方式,如果开始时间和结束时间是同一个日期,就查不出来了,一种解决方法是用DATE_FORMAT转一下日期,如:
<if test="startTime != null and startTime !='' ">
<![CDATA[ and DATE_FORMAT(create_time, '%Y-%m-%d') >= #{startTime} ]]>
</if>
<if test="endTime != null and endTime !='' ">
<![CDATA[ and DATE_FORMAT(create_time, '%Y-%m-%d') <= #{endTime} ]]>
</if>