From 80dfe8efa98bf4f748d7598e7bbd99eac8b430a8 Mon Sep 17 00:00:00 2001 From: Administrator <1157249554@qq.com> Date: Sat, 18 Apr 2020 13:26:55 +0800 Subject: [PATCH] =?UTF-8?q?validation=20Exception=20:=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=20=E5=BD=93=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=94=A8=E5=AF=B9=E8=B1=A1(=E9=9D=9E@response)?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E5=8F=82=E6=95=B0=E6=97=B6,=E6=8A=9B?= =?UTF-8?q?=E5=87=BABindException,=E8=AF=A5=E5=BC=82=E5=B8=B8=E8=A2=ABbody?= =?UTF-8?q?ValidExceptionHandler=E6=96=B9=E6=B3=95=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=97=B6=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E6=94=B9=E6=96=B9=E6=B3=95=E7=9A=84=E5=8F=82=E6=95=B0(MethodAr?= =?UTF-8?q?gumentNotValidException)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/exception/GlobalExceptionHandler.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 66020730..373f05ea 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()); + } } -- Gitee