diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/GlobalExceptionHandler.java b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/GlobalExceptionHandler.java index 6602073039eb3adbedda37f47f38d2b09e6d9fad..373f05eadcb72d8909b9b1b473ea1f8bb1263abd 100755 --- a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/GlobalExceptionHandler.java +++ b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/GlobalExceptionHandler.java @@ -52,17 +52,29 @@ public class GlobalExceptionHandler { } /** - * validation Exception + * validation Exception (以json形式传参) * * @param exception * @return R */ - @ExceptionHandler({MethodArgumentNotValidException.class, BindException.class}) + @ExceptionHandler({MethodArgumentNotValidException.class}) @ResponseStatus(HttpStatus.BAD_REQUEST) public R bodyValidExceptionHandler(MethodArgumentNotValidException exception) { List fieldErrors = exception.getBindingResult().getFieldErrors(); log.warn(fieldErrors.get(0).getDefaultMessage()); return R.failed(fieldErrors.get(0).getDefaultMessage()); } - + /** + * validation Exception (以form-data形式传参) + * + * @param exception + * @return R + */ + @ExceptionHandler({BindException.class}) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public R bindExceptionHandler(BindException exception) { + List fieldErrors = exception.getBindingResult().getFieldErrors(); + log.warn(fieldErrors.get(0).getDefaultMessage()); + return R.failed(fieldErrors.get(0).getDefaultMessage()); + } }