no message
Showing
1 changed file
with
9 additions
and
2 deletions
| ... | @@ -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 | /** | ... | ... |
-
Please register or sign in to post a comment