mybatis中Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang

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
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
	... 37 more
          <if test="startTime!=null and startTime!=''">
	     and CREATE_TIME &gt;=#{startTime}
	      </if>
	      <if test="endTime!=null and endTime!=''">
	     and CREATE_TIME &lt;=#{endTime}
	      </if>

时间类型与空字符串进行比较会抛异常,所以判断时间类型是否为空时,只需要去除!=‘’就可以了

          <if test="startTime!=null">
	     and CREATE_TIME &gt;=#{startTime}
	      </if>
	      <if test="endTime!=null">
	     and CREATE_TIME &lt;=#{endTime}
	      </if>

另外一种是需要设置pojo类中该属性为Stirng类型,同时数据库需要转换成Date类型,这里使用的oracle

	      <if test="startTime!=null and startTime!=''">
	     and CREATE_TIME &gt;=to_date(#{startTime},'yyyy-mm-dd')
	      </if>
	      <if test="endTime!=null and endTime!=''">
	     and CREATE_TIME &lt;=to_date(#{endTime},'yyyy-mm-dd')
	      </if>

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值