企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ @ControllerAdvice public class GraceExceptionHandler { @ExceptionHandler(FileSizeLimitExceededException.class) @ResponseBody public JSONResult returnMaxFileSizeLimit(FileSizeLimitExceededException e){ return JSONResult.errorMsg("文件大小不能超过500kb"); } @ExceptionHandler(MyCustomException.class) @ResponseBody public JSONResult returnMyCustomException(MyCustomException e){ return JSONResult.errorMsg(e.getMessage()); } } ~~~ @ControllerAdvice 实现全局异常处理,只需要定义类 * 全局异常处理 (@ExceptionHandler) * 全局数据绑定 (@InitBinder) * 全局数据预处理 (@ModelAttribute) ![](https://img.kancloud.cn/f6/bc/f6bc69c651aa9376cfecb684035956bc_644x262.png) ![](https://img.kancloud.cn/6e/1f/6e1f03ad1d47db079d805757b91e81ad_477x142.png) ![](https://img.kancloud.cn/87/5f/875f609a9c3cc3526ed0ca8cee6576f4_738x324.png) ![](https://img.kancloud.cn/f5/d8/f5d825cbcc38f07ff6ea26d6766bba88_445x47.png) 详解 https://blog.csdn.net/wangxinyao1997/article/details/103710843