基于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);
}
}
网友评论