package com.deity.test.exception;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
/**
* 使用AOP全局處理異常
* create by admin at 2018-10-9 23:33:15
*/
@ControllerAdvice
public class MyExceptionHandler {
@ExceptionHandler(value = Exception.class)
public String handleGlobalException(Exception exception,Model model){
model.addAttribute("message",exception.getMessage());
return "error";
}
}
在error.html頁(yè)面顯示錯(cuò)誤信息,并返回首頁(yè)
<div>
<h3><span th:text="${message}"></span></h3>
<a href="/">前往首頁(yè)</a>
</div>