如何使用 SpringTemplate + JDBCTemplate 作为 sql 查询的一部分发送日期列表

How to send List of dates as part of sql query using SpringTemplate + JDBCTemplate

好吧,我有这样的查询:

SELECT * FROM table WHERE someDate IN (date1, date2, date3);

我正在尝试使用 ST (SpringTemplate) 构建它并使用 JDBCTemplate 进行查询。

如果我只需要传递一个日期,我可以使用:

stringTemplateInstance.add("someColKey",dateInstance);

但是我怎样才能发送日期列表以便 IN 子句得到它呢?

现在,我正在使用 StringUtils.collectionToCommaDelimitedString(dateListForQuery); 查询(我不喜欢)。

放弃 StringTemplateJdbcTemplate 并切换到 NamedParameterJdbcTemplate

String query = "select * from table where someDate in (:dates)";
Map<String, Object> params = new HashMap<String, Object>();
params.put("dates", yourlistofdates);

List<YourResultType> result = template.query(query, params, new YourResultTypeRowMapper());

就这些了。