public List<Vehicle> findByApplicationId(String applicationId) {
// example application id is a string like 12345
MapSqlParameterSource sqlParameterSource = new MapSqlParameterSource();
sqlParameterSource.addValue("applicationId", applicationId);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("SELECT make, model");
stringBuilder.append(" FROM vehicle");
stringBuilder.append(" WHERE model IN (SELECT id FROM auto WHERE model_app IN (");
stringBuilder.append(":applicationId");
stringBuilder.append("))");
// in the resulting query the applicationId must appear
// as '12345', meaning with single quotes around it
return jdbcTemplate.query(stringBuilder.toString(), sqlParameterSource,
// lambda used as row mapper
(resultSet, rowNumber) -> {...
...
我试图在name参数周围加上双单引号,如中所示
stringBuilder.append("'':applicationId''");
,这不起作用。我尝试了单引号和许多其他的单引号和双引号的组合,这些都是基于我所看到的其他答案。似乎无法得到它。