我有两个DAO方法
public EUser getEUserById(Integer id) {
NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(getJdbcTemplate());
String sql = "SELECT * FROM users WHERE id = :id";
Map<String, Object> params = new HashMap<String, Object>();
params.put("id", id);
EUser e = (EUser) template.queryForObject(sql, params, new EUserRowMapper());
return e;
}
public List<EUser> getEUsers() {
String sql = "SELECT * FROM users";
List<EUser> es = getJdbcTemplate().query(sql, new EUserRowMapper());
return es;
}
Row-mapper
本身:
private class EUserRowMapper implements RowMapper<EUser> {
public EUser mapRow(ResultSet rs, int arg1)
throws SQLException {
EUser e = new EUser();
e.setId(rs.getInt("id"));
e.setName(rs.getString("name"));
//etc
return e;
}
}
但在我阅读有关这些方法的文件后,我对自己的选择表示怀疑。在ResultSetExtractor或RowMapper使用哪种更合适?