Commit 328a7206 authored by liaozan's avatar liaozan 🏀

Polish

parent 7d4b5319
......@@ -18,7 +18,6 @@ import java.util.StringJoiner;
public class ValidationMessageBuilder {
public static String buildBindingErrorMsg(BindingResult bindingResult) {
String prefix = "参数验证失败: ";
StringJoiner joiner = new StringJoiner(", ");
for (ObjectError error : bindingResult.getAllErrors()) {
String errorMessage = Optional.ofNullable(error.getDefaultMessage()).orElse("验证失败");
......@@ -30,17 +29,16 @@ public class ValidationMessageBuilder {
}
joiner.add(source + " " + errorMessage);
}
return prefix + joiner;
return joiner.toString();
}
public static String buildConstraintViolationErrorMsg(Set<ConstraintViolation<?>> constraintViolations) {
String prefix = "参数验证失败: ";
public static <T> String buildConstraintViolationErrorMsg(Set<ConstraintViolation<T>> constraintViolations) {
StringJoiner joiner = new StringJoiner(", ");
for (ConstraintViolation<?> violation : constraintViolations) {
String propertyPath = violation.getPropertyPath().toString();
joiner.add(getActualProperty(propertyPath) + " " + violation.getMessage());
}
return prefix + joiner;
return joiner.toString();
}
private static String getActualProperty(String propertyPath) {
......
......@@ -7,7 +7,8 @@ import org.apache.commons.collections4.CollectionUtils;
import javax.validation.ConstraintViolation;
import java.util.Set;
import java.util.stream.Collectors;
import static com.schbrain.common.util.support.ValidationMessageBuilder.buildConstraintViolationErrorMsg;
/**
* @author liaozan
......@@ -27,11 +28,10 @@ public class ExcelBeanReadListener<T> extends ExcelReadListenerBase<T> {
}
protected void collectErrorMsg(AnalysisContext context, Set<ConstraintViolation<T>> violations) {
String errorMsg = violations.stream().map(ConstraintViolation::getMessage).collect(Collectors.joining(","));
ReadSheetHolder currentSheet = context.readSheetHolder();
String sheetName = currentSheet.getSheetName();
Integer rowIndex = currentSheet.getRowIndex();
getErrors().put(sheetName, rowIndex + 1, errorMsg);
getErrors().put(sheetName, rowIndex + 1, buildConstraintViolationErrorMsg(violations));
}
}
\ No newline at end of file
}
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