getAjaxerror 即使加了 @ResponseBody 注解仍然報(bào) TemplateInputException 異常
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "err/getAjaxerror", template might not exist or might not be accessible by any of the configured Template Resolvers
@RequestMapping("getAjaxerror")
@ResponseBody
public?IMoocJSONResult?getAjaxerror()?{
int?a?=?1?/?0;
int?b?=?a;
return?IMoocJSONResult.ok();
}
2019-01-02
用@RestControllerAdvice
2018-05-17
你在后端接口添加@RequestBody是沒(méi)有用的,因?yàn)樗粫?huì)返回你的
return?IMoocJSONResult.ok();這個(gè)結(jié)果。在執(zhí)行方法體里的int?a?=?1?/?0;的時(shí)候會(huì)被異常捕獲機(jī)制捕獲在統(tǒng)一處理異常的代碼里,已經(jīng)確定了返回格式為:這是老師的代碼:
返回的格式不是JSON,使用的返回體的工具類只是對(duì)結(jié)果的封裝,所以會(huì)報(bào)錯(cuò),你會(huì)發(fā)現(xiàn)ajax處理返回請(qǐng)求的時(shí)候彈出的alert是:
alert("error");是這一部分的
在前一節(jié)沒(méi)有將異常處理統(tǒng)一的時(shí)候,單獨(dú)處理ajax請(qǐng)求時(shí),彈出的alert是success塊中:
alert("發(fā)生異常"+data.msg);是這一部分的:
最后的報(bào)錯(cuò)的原因還是統(tǒng)一異常處類中類頭定義的
的原因
2018-04-10
/getAjaxerror