今天在开发springcloud微服务框架下功能时,PG数据库一条sql报错:
Cause: org.postgresql.util.PSQLException: 错误: 操作符不存在: date >= character varying 建议:没有匹配指定名称和参数类型的操作符. 您也许需要增加明确的类型转换. 位置:345
其实框架提示的很清楚了,改动也很简单,例子如下
// 原来的
<if test="endDate_start != '' and endDate_end != '' and endDate_start != null and endDate_end != null ">
and b.enddate between #{endDate_start} and #{endDate_end}
</if>
// 改动后的
<if test="endDate_start != '' and endDate_end != '' and endDate_start != null and endDate_end != null ">
and b.enddate between CAST( #{endDate_start} as date) and CAST( #{endDate_end} as date)
</if>
在使用SpringCloud微服务框架进行开发时,遇到PostgreSQL数据库中日期字段与字符串比较的SQL错误。通过在MyBatis中添加类型转换,将字符串参数转换为日期类型,成功解决了这一问题。
3485

被折叠的 条评论
为什么被折叠?



