mapper.xml中定义的postgre SQL语句运行时报错:org.postgresql.util.PSQLException: ERROR: syntax error at or near “$1“
SELECT * from m_user where resigndt >= now()- INTERVAL #{flag} and resigndt <= now();
是数据转换异常(例如:Integer和String间转换异常) ,
解决方法1.将#改成$,$可转换成数值类型,但是使用$无法防止Sql注入
解决办法2. 将 INTERVAL #{flag} 替换成 #{flag}::INTERVAL
SELECT * from m_user where resigndt >= now()- #{flag}::INTERVAL and resigndt <= now()
本文介绍了解决在MyBatis中使用PostgreSQL时遇到的SQL语法错误的方法。错误发生在使用占位符和时间间隔表达式时,通过两种方式可以解决此问题:一是替换符号避免SQL注入风险;二是修改INTERVAL参数的写法。

1561

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



