map bean转换 反射 泛型

来源:互联网 发布:ubuntu 打开端口 编辑:程序博客网 时间:2024/05/17 23:55

/**

把map转换成一个bean

**/

@SuppressWarnings("finally")

public Object transMap2Bean2(Map<String, Object> map, Object obj) {  
        if (map == null || obj == null) {  
            return null;  
        }  
        try {  
             BeanUtils.populate(obj, map);  
        } catch (Exception e) {  
            System.out.println("transMap2Bean2 Error " + e);  
        }finally{
        return obj;
        }

    }


/**
* 通过反射加载按顺序获取属性值
* @param args
* @throws IOException 
* @throws NoSuchMethodException 
* @throws SecurityException 
* @throws InvocationTargetException 
* @throws IllegalAccessException 
* @throws IllegalArgumentException 
*/
public static void beanToJson(String [] methodsArr,String [] attributesArr,Object o) throws IOException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {

Class<?> classType = o.getClass();

Method method = classType.getMethod("getRecordDay");

method.setAccessible(true);

Object object = method.invoke(o);

System.out.println((String)object);


}
/**
* 字符串转化为驼峰命名格式
* @param name
* @return
*/
public static String captureName(String name) {
if(name.length()>1){
name = name.substring(0, 1).toUpperCase() + name.substring(1);
}else{
name = name.substring(0, 1).toUpperCase();
}
       return  name;
      
    }

0 0