Issue
public List<User> getAll(){
jdbcTemplate.query(query, rs -> {
Map<Integer, User> userMap= new HashMap<>();
while (rs.next()) {
// adding elements
}
System.out.println(userMap.values()); // shows me correct result
return userMap.values(); // not returning
});
return null;
}
This method returning me null and ignoring return inside lambda function. How I can receive data which I got inside the lambda?
Solution
jdbcTemplate.query
will return whatever you returned on the lambda function, in this case. Look at the documentation here.
So you could do:
public List<User> getAll(){
return jdbcTemplate.query(query, rs -> {
Map<Integer, User> userMap= new HashMap<>();
while (rs.next()) {
// adding elements
}
return userMap.values();
});
}
Answered By - Mateus Bandeira