Java自定义错误

@ControllerAdvice
public class CustomHandle {

@ResponseBody
@ExceptionHandler(MethodArgumentNotValidException.class)
public String methodArgumentNotValidExceptionHandle(MethodArgumentNotValidException e) {
    List<ObjectError> allErrors = e.getAllErrors();
    List<String> errorsMessages = allErrors.stream()
            .map(error -> error.getDefaultMessage())
            .collect(Collectors.toList());
    return errorsMessages.toString();
}

}


扫描二维码,在手机上阅读!

发表评论

电子邮件地址不会被公开。 必填项已用*标注