修改springboot默认返回的异常消息结构
{
"timestamp": "2021-11-05 12:36:07",
"status": 404,
"error": "Not Found",
"path": "/xxx/ooo123"
}
修改这个结构体
①项目配置文件中增加
mvc:
throw-exception-if-no-handler-found: true
resources:
add-mappings: false
②增加异常跳转控制器
@ControllerAdvice
@Slf4j
public class ErrController {
@ExceptionHandler(Throwable.class)
@ResponseBody
public String handleExceptions(Throwable e) {
log.info("============{}",e.getMessage());
return "{"code":1,"data":null,"bizMsg":"error-123","bizCode":20000}";
}
}
③重启工程



