06534673 by chentao

no message

1 parent 4ef82288
...@@ -25,6 +25,7 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchExcep ...@@ -25,6 +25,7 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchExcep
25 import javax.servlet.http.HttpServletRequest; 25 import javax.servlet.http.HttpServletRequest;
26 import javax.validation.ConstraintViolation; 26 import javax.validation.ConstraintViolation;
27 import javax.validation.ConstraintViolationException; 27 import javax.validation.ConstraintViolationException;
28 import java.util.Objects;
28 29
29 /** 30 /**
30 * 全局异常处理器 31 * 全局异常处理器
...@@ -186,8 +187,14 @@ public class GlobalExceptionHandler { ...@@ -186,8 +187,14 @@ public class GlobalExceptionHandler {
186 @ExceptionHandler(MethodArgumentNotValidException.class) 187 @ExceptionHandler(MethodArgumentNotValidException.class)
187 public R<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { 188 public R<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
188 log.error(e.getMessage()); 189 log.error(e.getMessage());
189 String message = e.getBindingResult().getFieldError().getDefaultMessage(); 190 if(Objects.nonNull(e.getBindingResult().getFieldError())) {
190 return R.fail(message); 191 String message = e.getBindingResult().getFieldError().getDefaultMessage();
192 return R.fail(message);
193 }
194 else{
195 String message = e.getBindingResult().getGlobalError().getDefaultMessage();
196 return R.fail(message);
197 }
191 } 198 }
192 199
193 /** 200 /**
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!