StringsUtil.java 830 字节
package com.jkdata.tool;

import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;

public class StringsUtil {

    //Object转Map
    public static Map<String, Object> getObjectToMap(Object obj) {
        Map<String, Object> map = new LinkedHashMap<String, Object>();
        try{
            Class<?> clazz = obj.getClass();
            for (Field field : clazz.getDeclaredFields()) {
                field.setAccessible(true);
                String fieldName = field.getName();
                Object value = field.get(obj);
                if (value == null) {
                    value = "";
                }
                map.put(fieldName, value);
            }
            return map;
        }catch (Exception e){
            return new LinkedHashMap<String, Object>();
        }
    }
}