例如,如何處理這種控制器的操作方法的驗證錯誤和可能的例外:如何處理RESTful Spring MVC控制器中的驗證錯誤和異常?
@RequestMapping(method = POST)
@ResponseBody
public FooDto create(@Valid FooDTO fooDto, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return null; // what to do here?
// how to let the client know something has gone wrong?
} else {
fooDao.insertFoo(fooDto); // What to do if an exception gets thrown here?
// What to send back to the client?
return fooDto;
}
}
發回相應的錯誤響應和/或代碼。我猜,我不明白這個問題。 – 2012-02-12 03:16:35
該操作返回一個'FooDTO',如何用一些驗證錯誤消息發回適當的響應? – 2012-02-12 06:12:06