Imagine I have the following DAO method:
public Employee getEmployeeById(Integer id){
NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate());
String sql = "SELECT * FROM users WHERE id = :userId";
Map<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put("userId", id);
return jdbcTemplate.queryForObject(sql, parameterMap, new EmployeeRowMapper());// Throws
//EmptyResultDataAccessException
}
The DAO method is used by the controller method:
public class EmployeeListController{
@Resource(name = "employeeDAO")
private EmployeeDAO employeeDAO;
@RequestMapping(value="/{empId}", method=RequestMethod.GET)
public String getEmployeeById(@PathVariable String empId, Model model){
model.addAttribute("employee", employeeDAO.getEmployeeById(Integer.valueOf(empId)));
return "employeesList";
}
}
Where would be better to handle the Exception? In the controller's method or the DAO's method? I think, that in the controller it would be, because otherwise we should return the Object with empty properties, which is not good. Is it correct?
Aucun commentaire:
Enregistrer un commentaire