JavaBean对象与Map对象互相转化
程序员文章站
2022-05-12 12:58:26
import java.util.Map; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.beanutils.BeanUtils; /*** * JavaBean对象与Map对象互相转化 */ publi... ......
import java.util.map; import org.apache.commons.beanutils.beanmap; import org.apache.commons.beanutils.beanutils; /*** * javabean对象与map对象互相转化 */ public class convermaptoobject { public static object maptoobject(map<string, object> map, class<?> beanclass) throws exception { if (map == null){ return null; } object obj = beanclass.newinstance(); beanutils.populate(obj, map); return obj; } public static map<?, ?> objecttomap(object obj) { if (obj == null){ return null; } return new beanmap(obj); } }