Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
s_guodong
gjjs-bd-common
Commits
32582570
Commit
32582570
authored
Dec 29, 2023
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化自定义vo赋值 和 校验
parent
18b36fb0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
ReflectUtil.java
...ness/src/main/java/com/ceb/gjjs/mda/util/ReflectUtil.java
+5
-0
ValidatorUtil.java
...ss/src/main/java/com/ceb/gjjs/mda/util/ValidatorUtil.java
+35
-0
No files found.
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/util/ReflectUtil.java
View file @
32582570
...
@@ -69,6 +69,10 @@ public class ReflectUtil {
...
@@ -69,6 +69,10 @@ public class ReflectUtil {
declaredField
.
set
(
baseVo
,
o
);
declaredField
.
set
(
baseVo
,
o
);
}
else
{
}
else
{
// 对象类型
// 对象类型
if
(
type
==
f
.
getType
())
{
// 相同的class 直接赋值
declaredField
.
set
(
baseVo
,
o
);
}
else
{
Object
typeO
=
type
.
newInstance
();
Object
typeO
=
type
.
newInstance
();
String
s
=
setValue2RequestVo
(
o
,
f
.
getType
(),
typeO
,
type
);
String
s
=
setValue2RequestVo
(
o
,
f
.
getType
(),
typeO
,
type
);
if
(!
StringUtils
.
isBlank
(
s
))
{
if
(!
StringUtils
.
isBlank
(
s
))
{
...
@@ -76,6 +80,7 @@ public class ReflectUtil {
...
@@ -76,6 +80,7 @@ public class ReflectUtil {
}
}
declaredField
.
set
(
baseVo
,
typeO
);
declaredField
.
set
(
baseVo
,
typeO
);
}
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// Class<?> superclass = baseVoClass.getSuperclass();
// Class<?> superclass = baseVoClass.getSuperclass();
// try {
// try {
...
...
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/util/ValidatorUtil.java
View file @
32582570
...
@@ -31,6 +31,9 @@ public class ValidatorUtil {
...
@@ -31,6 +31,9 @@ public class ValidatorUtil {
CHECK_ERR_MSG
.
remove
();
CHECK_ERR_MSG
.
remove
();
return
"参数校验错误["
+
s
+
"]"
;
return
"参数校验错误["
+
s
+
"]"
;
}
}
if
(
obj
==
null
)
{
return
""
;
}
Class
<?>
aClass
=
obj
.
getClass
();
Class
<?>
aClass
=
obj
.
getClass
();
Field
[]
fields
=
aClass
.
getDeclaredFields
();
Field
[]
fields
=
aClass
.
getDeclaredFields
();
for
(
Field
f
:
fields
)
{
for
(
Field
f
:
fields
)
{
...
@@ -41,6 +44,18 @@ public class ValidatorUtil {
...
@@ -41,6 +44,18 @@ public class ValidatorUtil {
o
=
f
.
get
(
obj
);
o
=
f
.
get
(
obj
);
}
catch
(
IllegalAccessException
e
)
{
}
catch
(
IllegalAccessException
e
)
{
}
}
// 集合
if
(
type
.
isAssignableFrom
(
List
.
class
))
{
List
list
=
(
List
)
o
;
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Object
e
=
list
.
get
(
i
);
String
check
=
check
(
e
);
if
(
StringUtils
.
isNotBlank
(
check
))
{
return
check
;
}
}
}
else
if
(
isPrimate
(
type
))
{
// 基本数据类型
if
(
f
.
isAnnotationPresent
(
Length
.
class
))
{
if
(
f
.
isAnnotationPresent
(
Length
.
class
))
{
Length
length
=
f
.
getAnnotation
(
Length
.
class
);
Length
length
=
f
.
getAnnotation
(
Length
.
class
);
int
max
=
length
.
max
();
int
max
=
length
.
max
();
...
@@ -165,9 +180,29 @@ public class ValidatorUtil {
...
@@ -165,9 +180,29 @@ public class ValidatorUtil {
return
"参数校验错误[时间格式不正确]"
;
return
"参数校验错误[时间格式不正确]"
;
}
}
}
}
}
else
if
(
type
.
getName
().
contains
(
"com"
))
{
// 对象类型
String
check
=
check
(
o
);
if
(
StringUtils
.
isNotBlank
(
check
))
{
return
check
;
}
}
}
}
return
""
;
return
""
;
}
}
private
static
boolean
isPrimate
(
Class
aclass
)
{
return
aclass
==
String
.
class
||
aclass
==
BigDecimal
.
class
||
aclass
==
Date
.
class
||
aclass
==
Integer
.
TYPE
||
aclass
==
Double
.
TYPE
||
aclass
==
Float
.
TYPE
||
aclass
==
Long
.
TYPE
||
aclass
.
isPrimitive
();
}
}
}
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