Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vehicle-quality-review
Project
Project
Details
Activity
Releases
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
王飞
vehicle-quality-review
Commits
100c6ea9
Commit
100c6ea9
authored
Mar 08, 2024
by
wdy
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
http://gitlab.91isoft.com:90/wangfei/vehicle-quality-review
into wangdingyi
parents
63a53733
bb64430b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
BeanUtils.java
.../src/main/java/com/ruoyi/common/utils/bean/BeanUtils.java
+29
-0
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/utils/bean/BeanUtils.java
View file @
100c6ea9
package
com
.
ruoyi
.
common
.
utils
.
bean
;
import
java.beans.BeanInfo
;
import
java.beans.Introspector
;
import
java.beans.PropertyDescriptor
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -107,4 +110,30 @@ public class BeanUtils extends org.springframework.beans.BeanUtils
{
return
m1
.
substring
(
BEAN_METHOD_PROP_INDEX
).
equals
(
m2
.
substring
(
BEAN_METHOD_PROP_INDEX
));
}
public
static
<
M
>
void
mergeObject
(
M
target
,
M
source
)
{
BeanInfo
beanInfo
=
null
;
try
{
beanInfo
=
Introspector
.
getBeanInfo
(
target
.
getClass
());
// Iterate over all the attributes
for
(
PropertyDescriptor
descriptor
:
beanInfo
.
getPropertyDescriptors
())
{
// Only copy writable attributes
if
(
descriptor
.
getWriteMethod
()
!=
null
)
{
Object
originalValue
=
descriptor
.
getReadMethod
()
.
invoke
(
target
);
// Only copy values where the destination values is null
if
(
originalValue
==
null
)
{
Object
defaultValue
=
descriptor
.
getReadMethod
().
invoke
(
source
);
descriptor
.
getWriteMethod
().
invoke
(
target
,
defaultValue
);
}
}
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"merge objects error"
,
e
);
}
}
}
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