Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
schbrain-parent
Commits
328a7206
Commit
328a7206
authored
Aug 15, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
7d4b5319
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
9 deletions
+7
-9
commons/common-util/src/main/java/com/schbrain/common/util/support/ValidationMessageBuilder.java
...chbrain/common/util/support/ValidationMessageBuilder.java
+3
-5
commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelBeanReadListener.java
...on/util/support/excel/listener/ExcelBeanReadListener.java
+4
-4
No files found.
commons/common-util/src/main/java/com/schbrain/common/util/support/ValidationMessageBuilder.java
View file @
328a7206
...
...
@@ -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
)
{
...
...
commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelBeanReadListener.java
View file @
328a7206
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment