原配置 <if test="startTime != null and startTime != ''"> and a.start_time <![CDATA[>=]]> #{startTime} </if> <if test="endTime != null and endTime != ''"> and a.end_time <![CDATA[<=]]> #{endTime}
原因:
这个错误是由于mybatis版本问题导致,这个版本中时间不能与空字符串进行比较。3.3.*版本应该都会有这个问题。
解决:
不判断是否为空字符
<if test="startTime != null"> and a.start_time <![CDATA[>=]]> #{startTime} </if> <if test="endTime != null "> and a.end_time <![CDATA[<=]]> #{endTime} </if>
另进行日期比较可以使用date()方法,所以结果应该为
<if test="startTime != null"> and date(a.start_time) <![CDATA[>=]]>date(#{startTime,jdbcType=TIMESTAMP}) </if> <if test="endTime != null "> and date(a.end_time ) <![CDATA[<=]]> date(#{endTime,jdbcType=TIMESTAMP}) </if>