Springboot 异常处理
@RestControllerAdvice
public class ExceptionHandlerController {
@ExceptionHandler(value = {ArithmeticException.class})
public String ArithmeticExceptionHandler(ArithmeticException e){
return "算数异常"+e.toString();
}
}
这样就可以了 让我们来测试一下
@GetMapping("/testServletApi")
public String testServletApi(HttpServletRequest request) {
int a =10/0;
return "testServletApi";
}