如何替换逗号中的参数?

How to replace param in commas?

我尝试用 namedParameterJdbcTemplate 替换 commans 包裹的参数,但它不起作用:

此代码(groovy)

def params = [hours: 24]
def query = "SELECT count(*) FROM Movie WHERE (now() - last_updated) < interval ':hours hours'"
def rowCount = namedParameterJdbcTemplate.queryForInt(query, params);

returns

nested exception is org.postgresql.util.PSQLException: ERROR: invalid input syntax for type interval: ":hours hours"

如何用namedParameterJdbcTemplate替换逗号中的参数?

帮助了我。这是固定版本 - 它可以工作,但我不确定这是解决问题的最佳方法:

def params = [hoursInterval: hours + " hours"]
def query = "SELECT count(*) FROM Movie WHERE (now() - last_updated) < :hoursInterval::INTERVAL"
def rowCount = namedParameterJdbcTemplate.queryForInt(query, params);