反射的对象的属性,方法

来源:互联网 发布:windows下的等宽字体 编辑:程序博客网 时间:2024/05/29 14:27
    
    public static void setFieldValue(StudentInfo studentinfo,String filedName,Object filedValue){
      if (null==studentinfo) {
    studentinfo=new StudentInfo();
   }
      try {
    //
       if (null!=filedName) {
        MethodUtils.invokeMethod(studentinfo, "set"+filedName.substring(0, 1).toUpperCase()+filedName.substring(1, filedName.length()), filedValue);
       }
   } catch (NoSuchMethodException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
 }