我有这个方法:
private File isFileValid(@Valid File file, Errors errors) {
if (errors.hasErrors()) {
List<ConstraintViolation<?>> violationsList = new ArrayList<>();
for (ObjectError e : errors.getAllErrors()) {
violationsList.add(e.unwrap(ConstraintViolation.class));
}
Map<String, Object> data = new HashMap<>();
// hash map ? instead of stringbuilder
// Construct a helpful message for each input violation
for (ConstraintViolation<?> violation : violationsList) {
data.put(violation.getPropertyPath().toString(), violation.getMessage());
}
throw new CustomValidationException("Invalid fields!", data);
}
return file;
}
我这样称呼它:
isFileValid(newFile);
调用方法时如何传递errors对象?
暂无答案!
目前还没有任何答案,快来回答吧!