mybatis-plus 时间大于小于问题

错误描述

org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: org.postgresql.util.PSQLException: FEHLER: Operator existiert nicht: timestamp without time zone > character varying
  建议:Kein Operator stimmt mit dem angegebenen Namen und den Argumenttypen überein. Sie müssen möglicherweise ausdrückliche Typumwandlungen hinzufügen.
  位置:59
### The error may exist in boxin/zdxb/mapper/CheckinQuestionMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT  *  FROM t_checkin_question     WHERE (create_time > ?)
### Cause: org.postgresql.util.PSQLException: FEHLER: Operator existiert nicht: timestamp without time zone > character varying
  建议:Kein Operator stimmt mit dem angegebenen Namen und den Argumenttypen überein. Sie müssen möglicherweise ausdrückliche Typumwandlungen hinzufügen.
  位置:59
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: FEHLER: Operator existiert nicht: timestamp without time zone > character varying
  建议:Kein Operator stimmt mit dem angegebenen Namen und den Argumenttypen überein. Sie müssen möglicherweise ausdrückliche Typumwandlungen hinzufügen.
  位置:59
        at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101) ~[spring-jdbc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88) ~[mybatis-spring-2.0.3.jar!/:2.0.3]
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) ~[mybatis-spring-2.0.3.jar!/:2.0.3]
        at com.sun.proxy.$Proxy85.selectOne(Unknown Source) ~[na:na]
        at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159) ~[mybatis-spring-2.0.3.jar!/:2.0.3]
        at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:108) ~[mybatis-plus-core-3.3.0.jar!/:3.3.0]
        at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:96) ~[mybatis-plus-core-3.3.0.jar!/:3.3.0]
        at com.sun.proxy.$Proxy112.selectOne(Unknown Source) ~[na:na]
        at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.getOne(ServiceImpl.java:267) ~[mybatis-plus-extension-3.3.0.jar!/:3.3.0]
        at com.baomidou.mybatisplus.extension.service.IService.getOne(IService.java:191) ~[mybatis-plus-extension-3.3.0.jar!/:3.3.0]

错误代码

return getOne(new QueryWrapper<CheckinQuestion>().gt("create_time", DateUtil.today())));

问题分析

时间比较时,必须传入 JDK 的 Date 类型,不支持字符串。
注:本项目中使用了 Hutool 的 DateUtil 工具类。

正确代码

        return getOne(new QueryWrapper<CheckinQuestion>().gt("create_time", DateUtil.parse(DateUtil.today()).toJdkDate()));
  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值