Created
April 28, 2017 15:31
-
-
Save solaris33/2b1ef0808da3a6d68da9320a94d603da to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// RowMapper using Anonymous Class | |
List<User> users = jdbcTemplate.query( | |
"SELECT USER_ID, USERNAME FROM USER", new RowMapper<User>() { | |
@Override | |
public User mapRow(ResultSet rs, int rowNum) throws SQLException { | |
User user = new User(); | |
user.setUserId(rs.getLong("USER_ID")); | |
user.setUsername(rs.getString("USERNAME")); | |
return user; | |
} | |
}); | |
// RowMapper using Lambda Expression | |
List<User> users = jdbcTemplate.query( | |
"SELECT USER_ID, USERNAME FROM USER", (rs, rowNum) -> { | |
User user = new User(); | |
user.setUserId(rs.getLong("USER_ID")); | |
user.setUsername(rs.getString("USERNAME")); | |
return user; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment