标签:resolve map public 展示 except object jackson 异常 Servle
设置全局异常,将异常信息指定内容展示给前端页面,保证程序的安全性
@Slf4j
@Component
public class ExceptionResolver implements HandlerExceptionResolver {
@Override
public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
log.error("{} Exception",httpServletRequest.getRequestURI(),e);
ModelAndView modelAndView = new ModelAndView(new MappingJacksonJsonView());
//当使用Jackson 2.x.时,使用对应的MappingJackson2JsonView, 这里使用的是1.9
modelAndView.addObject("status",ResponseCode.ERROR.getCode());
modelAndView.addObject("msg","接口异常,详情请查看服务端日志的异常信息");
modelAndView.addObject("data", e.toString());
return modelAndView;
}
}
标签:resolve map public 展示 except object jackson 异常 Servle
原文地址:https://www.cnblogs.com/FondWang/p/11711492.html