Commit b01f6e32 authored by yaobaizheng's avatar yaobaizheng

校验异常信息太臃肿 简化一下

parent 300e1368
...@@ -2,11 +2,13 @@ package com.lyy.user.config.exception; ...@@ -2,11 +2,13 @@ package com.lyy.user.config.exception;
import com.lyy.user.util.AjaxResult; import com.lyy.user.util.AjaxResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.validation.ValidationException; import javax.validation.ValidationException;
import java.util.stream.Collectors;
/** /**
* @author: zhouxudong * @author: zhouxudong
...@@ -32,7 +34,9 @@ public class GlobalExceptionHandler { ...@@ -32,7 +34,9 @@ public class GlobalExceptionHandler {
@ExceptionHandler(value = MethodArgumentNotValidException.class) @ExceptionHandler(value = MethodArgumentNotValidException.class)
public AjaxResult handlerException(MethodArgumentNotValidException e){ public AjaxResult handlerException(MethodArgumentNotValidException e){
log.error("发生参数校验异常:",e); log.error("发生参数校验异常:",e);
return AjaxResult.error(e.getMessage()); String error = e.getBindingResult().getAllErrors().stream().map(ObjectError::getDefaultMessage).distinct().collect(Collectors.joining(";"));
return AjaxResult.error(error);
// return AjaxResult.error(e.getMessage());
} }
@ExceptionHandler(value = ServiceException.class) @ExceptionHandler(value = ServiceException.class)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment