java tool

对象转Map

public static Map<String, Object> convertToMap(Object object) {
        Map<String, Object> params = new HashMap<String, Object>();
        BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(object);

        for (PropertyDescriptor column : bw.getPropertyDescriptors()) {
            params.put(column.getName(), bw.getPropertyValue(column.getName()));
        }

        return params;
    }


你可能感兴趣的:(java)