拋出一個 Error resolving template template might not exist or might not be accessible 的異常
在ajax的異常處理中,直接返回IMoocJSONResult是不行的,會再拋出一個
Error resolving template template might not exist or might not be accessible 的異常,而不是我們預想的byZero的異常,這時候需要使用MappingJackson2HttpMessageConverter把IMoocJSONResult手動寫入 HttpServletResponse中。
?
private static final String ERROR_VIEW = "error";
@Autowired
private MappingJackson2HttpMessageConverter jsonConverter;
???
@ExceptionHandler(value = Exception.class)
public Object error(HttpServletRequest request, HttpServletResponse response, Exception e) throws HttpMessageNotWritableException, IOException {
if(isAjax(request)) {
MyJSONResult result = MyJSONResult.errorException(e.getMessage());
??????????? jsonConverter.write(result, MediaType.APPLICATION_JSON, new ServletServerHttpResponse(response));
??????????? return null;
} else {
ModelAndView mav = new ModelAndView();
mav.addObject("exception",e);
mav.addObject("url", request.getRequestURL());
mav.setViewName(ERROR_VIEW);
return mav;
}
}
2020-11-22
學了了,我就說我的代碼一模一樣,結果缺不一樣
2019-06-19
一群人自以為懂了,瞎帶節(jié)奏
2019-04-29
大佬牛逼,我還郁悶為啥視頻的跑得起來呢,還特意從github下載了源碼
2019-04-18
盡信書不如無書,這哥們的是對的。
2019-04-15
老師的雖然跑起來了,但是alert輸出的結果不對,然后就不講了,這哥們的才是對的。
2019-01-13
試試
2018-11-10
2018-11-10
我能成功啊 不知道你這個異常怎么來的
2018-11-07
學習了,但是不知道為啥老師的代碼能夠跑成功,我反復看了幾遍以為他加了什么特殊配置,然而并沒有找到。。。
2018-09-20
你是對的。。。