当前位置:   article > 正文

JAVA项目做API,SpringMVC拦截异常并返回Json_java后端报错直接拦截返回具体的json

java后端报错直接拦截返回具体的json
public class ExceptionHandler implements HandlerExceptionResolver {


@Override
public ModelAndView resolveException(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex) {
Logger.getLogger(ex.getClass()).error("异常", ex);
// 输出错误Json
ModelAndView mav = new ModelAndView();
MappingJackson2JsonView view = new MappingJackson2JsonView();
Map<String, Object> result = new HashMap<String, Object>();
result.put("Code", -1);
result.put("Message",
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/799296
推荐阅读
相关标签
  

闽ICP备14008679号