getAjaxerror 即使加了 @ResponseBody 注解仍然報 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是沒有用的,因為他不會返回你的
return?IMoocJSONResult.ok();這個結果。在執行方法體里的int?a?=?1?/?0;的時候會被異常捕獲機制捕獲在統一處理異常的代碼里,已經確定了返回格式為:這是老師的代碼:
返回的格式不是JSON,使用的返回體的工具類只是對結果的封裝,所以會報錯,你會發現ajax處理返回請求的時候彈出的alert是:
alert("error");是這一部分的
在前一節沒有將異常處理統一的時候,單獨處理ajax請求時,彈出的alert是success塊中:
alert("發生異常"+data.msg);是這一部分的:
最后的報錯的原因還是統一異常處類中類頭定義的
的原因
2018-04-10
/getAjaxerror