亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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();
	}


正在回答

3 回答

@RestControllerAdvice

0 回復 有任何疑惑可以回復我~

你在后端接口添加@RequestBody是沒有用的,因為他不會返回你的

return?IMoocJSONResult.ok();這個結果。

在執行方法體里的int?a?=?1?/?0;的時候會被異常捕獲機制捕獲

在統一處理異常的代碼里,已經確定了返回格式為:

@ControllerAdvice

這是老師的代碼:

https://img1.sycdn.imooc.com//5afd4b970001341d10760224.jpg

返回的格式不是JSON,使用的返回體的工具類只是對結果的封裝,所以會報錯,你會發現ajax處理返回請求的時候彈出的alert是:

alert("error");

是這一部分的https://img1.sycdn.imooc.com//5afd4c9f0001357f08640656.jpg

在前一節沒有將異常處理統一的時候,單獨處理ajax請求時,彈出的alert是success塊中:

alert("發生異常"+data.msg);

是這一部分的:

https://img1.sycdn.imooc.com//5afd4cf70001041609320676.jpg

最后的報錯的原因還是統一異常處類中類頭定義的

@ControllerAdvice

的原因

0 回復 有任何疑惑可以回復我~

/getAjaxerror

0 回復 有任何疑惑可以回復我~
#1

逍遙明月 提問者

開始就是這么寫的,沒用。
2018-04-10 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

getAjaxerror 即使加了 @ResponseBody 注解仍然報 TemplateInputException 異常

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號