我在一个场景中抛出异常。由@ExceptionHandler
. 但是当抛出异常时,它说请求方法'POST'不支持
控制器代码
@RequestMapping(value = "abcd", method = {RequestMethod.POST,RequestMethod.GET })
public String testAbc(Model model, HttpServletRequest request) throws Exception {
//some piece of code
if(someCondition)
throw new Exception("No data found with id ");
}
ExceptionController 类中的代码
@ExceptionHandler(Exception.class)
public ModelAndView handleException(Exception ex, HttpServletRequest request, HttpServletResponse response) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("errorMessage", ex.getMessage());
modelAndView.addObject("errorDetails", ExceptionUtils.getStackTrace(ex));
modelAndView.setViewName("forward:errorPage");
return modelAndView;
}
不知道我做错了什么。