所有,我的控制器:
@RequestMapping(method = RequestMethod.GET, value = "/search")
@ResponseBody
public CemeteryRestResponse<List<String>> search(
@RequestParam("location") Location location) {
CemeteryRestResponse<List<String>> restResponse = new CemeteryRestResponse<List<String>>();
restResponse.setBody(new ArrayList<String>());
Long a = Long.valueOf("aaaa");
try {
for (PublicCemetery cemetery : cemeteryDao.findByLocation(location)) {
restResponse.getBody().add(cemetery.getNameCn());
}
} catch (Exception e) {
try {
throw new SQLException();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
restResponse.setSuccess(true);
return restResponse;
}
我在同一个控制器中的执行句柄方法:
@ExceptionHandler(value = { Exception.class, SQLException.class,
IllegalArgumentException.class, NumberFormatException.class })
@ResponseBody
public CemeteryRestResponse<String> exceptionHandler(Exception e,
SQLException e2, IllegalArgumentException e3,
NumberFormatException e4) {
CemeteryRestResponse<String> restResponse = new CemeteryRestResponse<String>();
restResponse.setFailureMessageCn("data base exception");
restResponse.setSuccess(false);
return restResponse;
}
当搜索方法 trhow SQLException 和 NumberFormatException @ExceptionHandler 无法处理时。谢谢!