1.使用@ExcpeitonHandler注解
在Controller类中,方法随便写,参数为Excepiton对象,是程序抛出的Exception,springmvc捕获并传到这里
@ExceptionHandler
public String testException(Exception e){
if(e instanceof TestException){
return "test2";
}else{
return "test1";
}
}
每次抛出的异常,springmvc会在该方法中进行处理