import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
/**
* @author : zanglikun
* @date : 2021/3/11 13:54
* @Version: 1.0
* @Desc : AOP 思想 统一异常处理
*/
@ControllerAdvice
public class UnitonException {
// 拦截 异常 到
@ExceptionHandler(myExpection.class)
public ResponseEntity oneException(myExpection e){
return ResponseEntity.badRequest().body("hello,world");
}
}
然后造一个异常,就可以处理了。
特殊说明: 解决问题的光鲜,藏着磕Bug的痛苦。 万物皆入轮回,谁也躲不掉! 以上文章,均是我实际操作,写出来的笔记资料,不会出现全文盗用别人文章!烦请各位,请勿直接盗用!