举个例子:如果开始时间和结束时间都是varchar类型,那么可以利用下面的方式去获取时间范围
<if test="startTime != null and startTime != ''">
<![CDATA[ and o.STARTTIME >= #{startTime}]]>
</if>
<if test="endTime != null and endTime != ''">
<![CDATA[ and o.ENDTIME <= #{endTime}]]>
</if>
转成时间函数写法
<if test="startTime != null and startTime != ''">
AND DATE_FORMAT(created_at, '%Y-%m-%d') <![CDATA[ >= ]]> DATE_FORMAT(#{startTime}, '%Y-%m-%d')
</if>
<if test="endTime != null and endTime != ''">
AND DATE_FORMAT(created_at, '%Y-%m-%d') <![CDATA[ <= ]]> DATE_FORMAT(#{endTime }, '%Y-%m-%d')
</if>