|
@@ -5,6 +5,8 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.security.access.AccessDeniedException;
|
|
|
import org.springframework.validation.BindException;
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
+import org.springframework.validation.FieldError;
|
|
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
import org.springframework.web.bind.MissingPathVariableException;
|
|
@@ -118,9 +120,20 @@ public class GlobalExceptionHandler
|
|
|
@ExceptionHandler(BindException.class)
|
|
|
public AjaxResult handleBindException(BindException e)
|
|
|
{
|
|
|
+ //wanghao 修改全局异常处理
|
|
|
+// log.error(e.getMessage(), e);
|
|
|
+// String message = e.getAllErrors().get(0).getDefaultMessage();
|
|
|
+// return AjaxResult.error(message);
|
|
|
+
|
|
|
log.error(e.getMessage(), e);
|
|
|
- String message = e.getAllErrors().get(0).getDefaultMessage();
|
|
|
- return AjaxResult.error(message);
|
|
|
+ BindingResult bindingResult = e.getBindingResult();
|
|
|
+ StringBuilder sb = new StringBuilder("校验失败:");
|
|
|
+ for (FieldError fieldError : bindingResult.getFieldErrors()) {
|
|
|
+ sb.append(fieldError.getField()).append(":").append(fieldError.getDefaultMessage()).append(", ");
|
|
|
+ }
|
|
|
+ String msg = sb.toString();
|
|
|
+ log.error(msg);
|
|
|
+ return AjaxResult.error(msg);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -129,9 +142,20 @@ public class GlobalExceptionHandler
|
|
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
|
public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e)
|
|
|
{
|
|
|
+// log.error(e.getMessage(), e);
|
|
|
+// String message = e.getBindingResult().getFieldError().getDefaultMessage();
|
|
|
+ //wanghao 修改全局异常处理
|
|
|
+
|
|
|
log.error(e.getMessage(), e);
|
|
|
- String message = e.getBindingResult().getFieldError().getDefaultMessage();
|
|
|
- return AjaxResult.error(message);
|
|
|
+ BindingResult bindingResult = e.getBindingResult();
|
|
|
+ StringBuilder sb = new StringBuilder("校验失败:");
|
|
|
+ for (FieldError fieldError : bindingResult.getFieldErrors()) {
|
|
|
+ sb.append(fieldError.getField()).append(":").append(fieldError.getDefaultMessage()).append(", ");
|
|
|
+ }
|
|
|
+ String msg = sb.toString();
|
|
|
+ log.error(msg);
|
|
|
+
|
|
|
+ return AjaxResult.error(msg);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -142,4 +166,7 @@ public class GlobalExceptionHandler
|
|
|
{
|
|
|
return AjaxResult.error("演示模式,不允许操作");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|