PSQL query is returning a list of 2 values name and count.
I want to put it to a single Hashmap and return values.
the query result will be like
name count
completed 2
successful 8
inprogress 1
I'm able to get the result in result variable. But in for loop I'm getting is Integer in entry.get("name") so I'm not able to put to finalresult.
The final output of this function will be Map<String, Integer> and it will be converted into JSON response to API by the controller.
{
"completed":2,
"successful":8,
"inprogress":1
}
Current Code
List<Map<String, Integer>> result = null;
Map<String, Integer> finalresult = new HashMap<>();
map.put("id", id);
result = sqlSession.selectList("com.class.getresult",map);
System.out.println(result);
if (!result.isEmpty()) {
for (Map<String, Integer> entry : result) {
finalresult.put(entry.get("name"), entry.get("count"));
}
}
return finalresult;
How do I get the name of from List?