public static <T> T
fillEntity(Class
<T> tEntity
,Map
<String,Object> objectMap
){
T entity
= ClassUtil
.createInstance(tEntity
,true);
if(null
==objectMap
|| objectMap
.isEmpty()){
return entity
;
}
List
<Field> fields
= Arrays
.asList(tEntity
.getDeclaredFields());
for(Map
.Entry
<String,Object> entry
: objectMap
.entrySet()){
Field field
=fields
.stream().filter(x
->x
.getName().equals(entry
.getKey())).findFirst().orElse(null
);
if(null
!= field
&& null
!= entry
.getValue()){
field
.setAccessible(true);
try {
field
.set(entity
, ConvertUtils
.convert(entry
.getValue(),field
.getType()));
} catch (IllegalAccessException e
) {
logger
.error("fillEntity field:{} value:{} error:{}",field
.getName(),entry
.getValue());
}
}
}
return entity
;
}
转载请注明原文地址:https://tech.qufami.com/read-14983.html