慕函数1174211
2018-09-20 23:04
在getAjacError方法里面除0操作,跑到ajacError.js里面,直接就进了error,无法请求成功??





将 @ControllerAdvice 换成 @RestControllerAdvice
进error是因为js无法识别你的data对象,因为你的data对象不是json格式,所以进入了你定义的回调函数的error方法。其实请求是成功的,只是你用的注解不是@RestControllerAdvice
@ExceptionHandler(value = Exception.class)
public void exceptionHandler(HttpServletRequest request, HttpServletResponse response,
Exception e, Model model) throws Exception {
if (isAjax(request)) {
// 向response中写json数据
response.setCharacterEncoding("utf-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter writer = response.getWriter();
writer.write(gson.toJson(JsonResult.errorException(e.getMessage())));
} else {
request.setAttribute("exception", e);
request.setAttribute("url", request.getRequestURL());
request.getRequestDispatcher("/templates/error.html").forward(request,
response);
}
}
同问啊
怎么解决的,我也感觉很奇怪
已根据@玩蜡笔小破孩同学的方法解决了问题,感谢
SpringBoot开发常用技术整合
102207 学习 · 530 问题
相似问题