Created
September 6, 2022 06:58
-
-
Save vahidhedayati/da89e8482aa6e9feb0b178af141d8788 to your computer and use it in GitHub Desktop.
Return a dynamic map regardless of query using namedParameterJdbcTemplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Map<String, Object>> result = namedParameterJdbcTemplate.query(query, whereParams, rs -> { | |
List<Map<String, Object>> rows = new ArrayList<>(); | |
ResultSetMetaData metaData = rs.getMetaData(); | |
int columnCount = metaData.getColumnCount(); | |
while (rs.next()) { | |
Map<String, Object> columns = new LinkedHashMap<>(); | |
for (int i = 1; i <= columnCount; i++) { | |
columns.put(metaData.getColumnLabel(i), rs.getObject(i)); | |
} | |
rows.add(columns); | |
} | |
return rows; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment