@ControllerAdvice
@ResponseBody
public class GlobalExceptionInterceptor {
@ExceptionHandler(value = Exception.class)
public String exceptionHandler(HttpServletRequest request, Exception e ) {
String failMsg = null;
if (e instanceof MethodArgumentNotValidException) {
// 拿到参数校验具体异常信息提示
failMsg = ((MethodArgumentNotValidException)e).getBindingResult().getFieldError().getDefaultMessage();
}
// 直接吐回给前端
return failMsg;
}
}