7.3异常处理

配置全局异常处理:
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
* @version 版权 Copyright(c)2019
* @ClassName:
* @Descripton: 全局异常处理机制
* @author: Shing
* @date: 2020-06-22 14:29
*/

/**
* 在带有@ControllerAdvice注解的类中,以上
* 所述的方法都会运用到整个应用程序所以的控制器
* 中带有@RequestMapping注解的方法上。
*/
@ControllerAdvice
public class AppWideExcetionHandler {

/**
* 当抛出RuntimeException方法时,将会委托
* 该方法来处理
* @return
*/
@ExceptionHandler({RuntimeException.class})
public String RuntimeExcetion(){
return "templates/error";
}

}





posted @ 2021-01-14 19:57  _Shing  阅读(123)  评论(0)    收藏  举报