Yes, it's possible in Spring if you use NamedParameterJdbcTemplate
or SimpleJdbcTemplate
with named parameters. List parameter can be set as a java.util.List
:
List<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
List<SomeObject> result = simpleJdbcTemplate.query("SELECT * FROM t WHERE c in (:list)",
new RowMapper<SomeObject>() { ... },
Collections.singletonMap("list", list));
In this case Spring internally creates the SQL query with the required number of placeholders based on the size of the actual list when replacing named parameters with ?
s.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…