【学习】SpringBoot之全局异常处理器

时间:2025-02-03 13:37:38
/**
* 全局异常处理器
**/
@ControllerAdvice
public class GlobalExceptionHandler { @ExceptionHandler(Exception.class)
@ResponseBody
public Map<String,Object> handlerException(Exception exception){
Map<String,Object> map = new HashMap<String ,Object>();
map.put("errorCode","500");
map.put("errorMsg",exception.toString());
return map;
} }