全局异常
@RestControllerAdvice
public class GlobalExceptionHandler {
/**
* 请求方式不支持
*/
@ExceptionHandler({ HttpRequestMethodNotSupportedException.class })
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public RespResult handleException(HttpRequestMethodNotSupportedException e)
{
return RespResult.error("系统异常");
}
/**
* 拦截未知的运行时异常
*/
@ExceptionHandler(RuntimeException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public RespResult notFount(RuntimeException e)
{
return RespResult.error("系统异常");
}
/**
* 系统异常
*/
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public RespResult handleException(Exception e)
{
return RespResult.error("系统异常");
}
}
跨域
https://baijiahao.baidu.com/s?id=1618332668780491799&wfr=spider&for=pc
标签:ResponseStatus,HttpStatus,Transsion,public,RespResult,异常,class From: https://www.cnblogs.com/yier-l/p/18092611