mybatis 3.4.6,日期字段做比较操作,日期字段为空时,报错
2018-04-06 18:04:26,614 INFO [OrderRelationController.java:345] : nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
### Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
2018-04-06 18:04:26,815 ERROR [MIBaseController.java:69] : 调用search接口。返回结果:{"body":{},"head":{"appVersion":"","dataVersion":"","deployVersion":"","msgCount":"","rspCode":"1","rspMsg":"查询失败"}}
经查是mybatis的bug,在对日期字段进行比较操作时,只能做null判断,不能做空串判断
<sql id="condition_sql">
<if test="startTime !=null and startTime !='' "> and ordertime >= #{startTime} </if>
<if test="endTime !=null and endTime !='' "> and ordertime <=#{endTime} </if>
</sql>
正确的配置如下:
<sql id="condition_sql">
<if test="startTime !=null"> and ordertime >= #{startTime} </if>
<if test="endTime !=null"> and ordertime <=#{endTime} </if>
</sql>