課程
/后端開(kāi)發(fā)
/Java
/SpringBoot開(kāi)發(fā)常用技術(shù)整合
在getAjacError方法里面除0操作,跑到ajacError.js里面,直接就進(jìn)了error,無(wú)法請(qǐng)求成功??
2018-09-20
源自:SpringBoot開(kāi)發(fā)常用技術(shù)整合 7-3
正在回答
publicclassHelloWorld{{"name":"\u767d\u5bcc\u7f8e","say":"\u54b1\u4eec\u7ed3\u5a5a\u5427!"}
將 @ControllerAdvice 換成 @RestControllerAdvice
進(jìn)error是因?yàn)閖s無(wú)法識(shí)別你的data對(duì)象,因?yàn)槟愕膁ata對(duì)象不是json格式,所以進(jìn)入了你定義的回調(diào)函數(shù)的error方法。其實(shí)請(qǐng)求是成功的,只是你用的注解不是@RestControllerAdvice
@ExceptionHandler(value?=?Exception.class) public?void?exceptionHandler(HttpServletRequest?request,?HttpServletResponse?response, ?????????????????????????????Exception?e,?Model?model)?throws?Exception?{ ????if?(isAjax(request))?{ ????????//?向response中寫(xiě)json數(shù)據(jù) ????????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); ????} }
同問(wèn)啊
怎么解決的,我也感覺(jué)很奇怪
已根據(jù)@玩蠟筆小破孩同學(xué)的方法解決了問(wèn)題,感謝
舉報(bào)
SpringBoot 極簡(jiǎn)開(kāi)發(fā)的框架整合利器
1 回答配置全局的異常捕獲時(shí),走ajax請(qǐng)求下面報(bào)錯(cuò)
3 回答視頻中ajax請(qǐng)求異常t彈出error?
1 回答異常捕獲后沒(méi)有進(jìn)入error頁(yè)面
1 回答 IDEA Springboot 異常捕獲信息,頁(yè)面沒(méi)輸出。
3 回答捕獲到了異常,但是做跳轉(zhuǎn)的時(shí)候失敗
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2022-03-25
publicclassHelloWorld{{"name":"\u767d\u5bcc\u7f8e","say":"\u54b1\u4eec\u7ed3\u5a5a\u5427!"}
2019-07-04
將 @ControllerAdvice 換成 @RestControllerAdvice
2019-06-19
進(jìn)error是因?yàn)閖s無(wú)法識(shí)別你的data對(duì)象,因?yàn)槟愕膁ata對(duì)象不是json格式,所以進(jìn)入了你定義的回調(diào)函數(shù)的error方法。其實(shí)請(qǐng)求是成功的,只是你用的注解不是@RestControllerAdvice
2019-04-01
2019-02-06
同問(wèn)啊
2018-10-18
怎么解決的,我也感覺(jué)很奇怪
2018-09-20
已根據(jù)@玩蠟筆小破孩同學(xué)的方法解決了問(wèn)題,感謝