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页面显示错误信息,并返回首页
<div>
<h3><span th:text="${message}"></span></h3>
<a href="/">前往首页</a>
</div>