企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
#### 实体类 ``` import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; @NoArgsConstructor @Setter @Getter @ToString public class ErrorMessage<T> { private Integer code; private String msg; private T data; } ``` #### 全局异常类 ``` // 辅助类,可以指定扫描范围 @ControllerAdvice public class GlobalExceptionHandler { // 表示拦截异常 @ExceptionHandler(RuntimeException.class) @ResponseBody public ErrorMessage<String> exceptionHandler(HttpServletRequest request, Exception exception){ ErrorMessage<String> errorMessage = new ErrorMessage<String>(); errorMessage.setCode(1); errorMessage.setMsg("访问异常"); errorMessage.setData(exception.getMessage()); return errorMessage; } } ```