1.对象转换成字符串
2.bean转换成map
import java.util.HashMap;
import java.util.Map;
import org.springframework.cglib.beans.BeanMap;
public class BeanUtils {
/**
* bean转换成map
* @param bean
* @return
*/
public static <T> Map<String, String> beanToMap(T bean) {
if (null == bean) {
return null;
}
Map<String, String> map = new HashMap<String, String>();
BeanMap beanMap = BeanMap.create(bean);
Object value;
for (Object key : beanMap.keySet()) {
value = beanMap.get(key);
if(null == value) {
continue;
}
map.put(String.valueOf(key), toString(value));
}
return map;
}
/**
* 对象转换成字符串
* @param obj
* @return
*/
public static String toString(Object obj) {
if(null == obj) {
return null;
}
return String.valueOf(obj);
}
}