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
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
panwangnan
schbrain-parent
Commits
4f574756
Commit
4f574756
authored
Jul 27, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish ValidationMessageBuilder
parent
f234110f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
commons/common-util/src/main/java/com/schbrain/common/util/support/ValidationMessageBuilder.java
...chbrain/common/util/support/ValidationMessageBuilder.java
+15
-4
No files found.
commons/common-util/src/main/java/com/schbrain/common/util/support/ValidationMessageBuilder.java
View file @
4f574756
package
com.schbrain.common.util.support
;
import
org.hibernate.validator.internal.engine.path.PathImpl
;
import
cn.hutool.core.text.StrPool
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.FieldError
;
import
org.springframework.validation.ObjectError
;
...
...
@@ -36,10 +37,20 @@ public class ValidationMessageBuilder {
String
prefix
=
"参数验证失败: "
;
StringJoiner
joiner
=
new
StringJoiner
(
", "
);
for
(
ConstraintViolation
<?>
violation
:
constraintViolations
)
{
PathImpl
propertyPath
=
(
PathImpl
)
violation
.
getPropertyPath
();
joiner
.
add
(
propertyPath
.
asString
(
)
+
" "
+
violation
.
getMessage
());
String
propertyPath
=
violation
.
getPropertyPath
().
toString
();
joiner
.
add
(
getActualProperty
(
propertyPath
)
+
" "
+
violation
.
getMessage
());
}
return
prefix
+
joiner
;
}
}
\ No newline at end of file
private
static
String
getActualProperty
(
String
propertyPath
)
{
if
(
StringUtils
.
isBlank
(
propertyPath
))
{
return
propertyPath
;
}
if
(!
propertyPath
.
contains
(
StrPool
.
DOT
))
{
return
propertyPath
;
}
return
propertyPath
.
substring
(
propertyPath
.
lastIndexOf
(
StrPool
.
DOT
)
+
1
);
}
}
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