示例,全局异常捕获处理:
// 抛出Exception异常
@GetMapping(value = "girls/getAge/{id}")
public void getAge(@PathVariable("id") Integer id) throws Exception{
girlService.getAge(id);
}
// 编写@ControllerAdvice
@ControllerAdvice
public class ExceptionHandle {
@ExceptionHandler(value = Exception.class)
@ResponseBody
public Result handle(Exception e) {
return ResultUtil.error(100, e.getMessage());
}
}
原文:https://www.cnblogs.com/vincenshen/p/10427886.html