jsonView
来源:6-3 接口请求全局异常处理-设计与验证

慕雪8553940
2020-02-18
老师您好,我在idea中创建的Spring Initializr项目。学到6-3接口请求全局变量的SpringExceptionResolver时,view:jsonView显示Cannot resolve MVC View ‘jsonView’ ,我该怎么在spring boot的环境里面解决这个问题呢?
1回答
-
你好,springboot就不走这个了,你对照这个修改一下吧。
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
@ExceptionHandler(value = RuntimeException.class)
@ResponseBody
public JsonData jsonErrorHandler(HttpServletRequest request, RuntimeException ex) throws Exception {
String url = request.getRequestURL().toString();
String defaultMsg = "System error";
JsonData result = null;
if (ex instanceof PermissionException || ex instanceof ParamException) {
result = JsonData.fail(ex.getMessage());
} else {
log.error("unknown json exception, url:" + url, ex);
result = JsonData.fail(defaultMsg);
}
return result;
}
}012020-02-19
相似问题