pg
limit #{pageIndex},#{pageSize}
LIMIT #{pageSize} OFFSET #{(pageIndex - 1) * pageSize}Mybatis中DateTime类型的参数 if 判断问题
原来写法
xml
<if test="startTime != null and startTime != ''">
AND tran.transaction_time>#{startTime}
</if>报错信息
org.mybatis.spring.MyBatisSystemException:
### Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: java.time.LocalDateTime and java.lang.Stringmybatis中对于时间参数进行比较时的一个bug。 如果拿传入的时间类型参数与空字符串’'进行对比判断则会引发异常. 所以在上面的代码中去掉空字符串判断, 只保留非空判断就正常了
xml
<if test="startTime != null">
AND tran.transaction_time>#{startTime}
</if>mybatis
org.springframework.jdbc.BadSqlGrammarException: Error attempting to get column 'log_time' from result set. Cause: org.postgresql.util.PSQLException: Cannot convert the column of type TIMESTAMPTZ to requested type java.time.LocalDateTime.
; bad SQL grammar []