1、需要的jar包
<dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>27.1-jre</version> </dependency>
此外,还导入了spring框架的一个包
import org.springframework.cglib.beans.BeanMap;
2、主要代码
private <T> Map<String,Object> beanToMap(T bean){ Map<String, Object> map = Maps.newHashMap(); if (null != bean){ BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()){ map.put(key+"",beanMap.get(key)); } } return map; }