springboot 使用jdbctemplate执行sql in操作
查询List<String> ids
String sql ="SELECT id FROM bz_project WHERE project_id='test2021'";
List<String> idsList = jdbcTemplate.queryForList(sql1, String.class);
用了NamedParameterJdbcTemplate类,然后通过:ids方式进行参数的匹配。
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource());
Map<String, Object> params = new HashMap<String, Object>();
sql1 = "UPDATE bz_user set del_flag='1' where id in (:ids)";
params.put("ids", idsList);
int update = namedParameterJdbcTemplate.update(sql1, params);