基于org.apache.commons.beanutils.BeanUtils工具類
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
</dependency>
public static void transMap2Bean(Map<String, Object> map, Object obj) {
if (map == null || obj == null) {
return;
}
try {
BeanUtils.populate(obj, map);
} catch (Exception e) {
System.out.println("transMap2Bean2 Error " + e);
}
}
public static Map<String, Object> transBean2Map(Object obj) {
if (obj == null) {
return new HashMap<>();
}
try {
return new BeanMap(obj)
} catch (Exception e) {
System.out.println("transBean2Map Error " + e);
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者