If a bean has list field , how can I use NamedParameterJdbcTemplate to insert the list of values to database using BeanPropertySqlParameterSource? If it's not possible then what should I use?
Asked
Active
Viewed 1,504 times
1 Answers
0
There is no direct way since there is no direct way to map a list of values to one column. There are any number of things you may be wanting it to do. This is about the closest option.
How to generate a dynamic "in (...)" sql list through Spring JdbcTemplate?
String query = "select * from table where columnName in (:listOfValues)";
List nameRecordIDs = new ArrayList();
// ...
// add values to collection, then
// ...
Map namedParameters = Collections.singletonMap("listOfValues", nameRecordIDs);
namedparameterJdbcTemplate.query(query, namedParameters,new MyMapper());