将 Map 映射到 类(Map转对象)


//import org.apache.commons.beanutils.BeanUtils;

 public static  T decode(Class clazz , Map msg){
        try {
            T cls = clazz.newInstance();
            Set.Entry> entrySet = msg.entrySet();
            for(Map.Entry entry : entrySet){
                BeanUtils.setProperty(cls,entry.getKey(),entry.getValue());
            }
            return cls;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

你可能感兴趣的:(java)