Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
legobackend
/
lego-manage
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
c8762aca
authored
2025-04-23 17:33:46 +0800
by
chentao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
no message
1 parent
1b3704df
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
2 deletions
lego-common/src/main/java/com/lego/common/annotation/AtLeastOneNonNullValidator.java
lego-common/src/main/java/com/lego/common/annotation/AtLeastOneNonNullValidator.java
View file @
c8762ac
package
com
.
lego
.
common
.
annotation
;
import
com.lego.common.annotation.AtLeastOneNonNull
;
import
com.lego.common.utils.StringUtils
;
import
javax.validation.ConstraintValidator
;
import
javax.validation.ConstraintValidatorContext
;
...
...
@@ -32,8 +33,11 @@ public class AtLeastOneNonNullValidator implements ConstraintValidator<AtLeastOn
field
.
setAccessible
(
true
);
// 设置私有字段可访问,以便读取值
System
.
out
.
println
(
field
.
getName
()+
"============"
+
field
.
get
(
object
)+
"!"
);
if
(
Objects
.
nonNull
(
field
.
get
(
object
)))
{
// 检查字段是否非空
System
.
out
.
println
(
field
.
getName
()+
"============"
+
field
.
get
(
object
)+
"&"
);
return
true
;
// 如果至少一个字段非空,返回true
String
value
=
String
.
valueOf
(
field
.
get
(
object
));
if
(
StringUtils
.
isNotEmpty
(
value
))
{
System
.
out
.
println
(
field
.
getName
()
+
"============"
+
field
.
get
(
object
)
+
"&"
);
return
true
;
// 如果至少一个字段非空,返回true
}
}
}
catch
(
NoSuchFieldException
|
IllegalAccessException
e
)
{
// 处理异常,例如记录日志等
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment