Commit 328a7206 authored by liaozan's avatar liaozan 🏀

Polish

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