@Validated 返回参数太乱处理
1.处理前
有参数:
通过接口校验时返回如下长串
2.处理后
处理代码
@RestControllerAdvice @Slf4j public class SysExceptionHandler { /** * 参数校验异常控制处理 * @param e * @return */ @ExceptionHandler(BindException.class) public Result<?> handleBindException(BindException e){ Result<Object> result = new Result<>(); BindingResult bindingResult = e.getBindingResult(); List<FieldError> fieldErrors = bindingResult.getFieldErrors(); JSONObject jsonObject = new JSONObject(); fieldErrors.forEach( fieldError -> { jsonObject.put(fieldError.getField(),fieldError.getDefaultMessage()); }); result.error500(jsonObject.toString()); return result; } {1.处理前 有参数: 通过接口校验时返回如下长串 2.处理后 处理代码 @RestControllerAdvice @Slf4j public class SysExceptionHandler { /** * 参数校验异常控制处理 * @param e * @return */ @ExceptionHandler(BindException.class) public Result handleBindException(BindException e){ Result