标签:else class cep http public style value equals head
@ControllerAdvice public class MyControllerAdvice { /** * 全局异常捕捉处理 * @param ex * @return */ @ResponseBody @ExceptionHandler(value = Exception.class) public Object errorHandler(HttpServletRequest request,HttpServletResponse response,Exception e) throws Exception{
e.printStackTrace(); if(isAjax(request)){
return JSONResult.errorException(e.getMessage());
}else{
ModelAndView mav = new ModelAndView();
mav.addObject("Exception",e);
mav.addObject("url",request.getRequestURL);
mav.setViewName(ERROR_VIEW);
return mav;
}
}
public static boolean isAjax(HttpServletRequest request){
return(httpRequest.getHeader("X-Requested-With") != null && "XMLHttpRequest".equalsIgnoreCase(((HttpServletRequest) request).getHeader("X-Requested-With").toString()));
}
}
标签:else class cep http public style value equals head
原文地址:https://www.cnblogs.com/taiguyiba/p/10235879.html