本帖最后由 zhuangwei_ 于 2010-08-06 07:29:07 编辑

解决方案 »

  1.   

    1.顺序问题:只要你foo类中变量的get方法的是按照变量顺序来的就没有问题。你可以通过Eclipse直接生成get/set方法,都是按照变量的顺序生成的。只要这个顺序定了,那么反射出来的顺序就是固定的。
    2.至于强制转化的过程,我觉得可以。因为excel支持的类型就那么几种。完全可以可以通过if else来判断。虽然扩展性不强。
      

  2.   


    1.顺序问题,可能我中途有调整过变量名的数量,粗心了把get/set方法顺序弄乱了,今天休息,星期一我去公司验证下。
    2.我不想在我处理生成Eecel的方法里去判断,如果那样判断肯定是没问题的,我想把判断的方法抽成一个函数,请问如何实现?
      

  3.   


    不对啊,Method[] methods = dtoClass.getDeclareMethods();
    里面的get方法顺序都是乱的。
      

  4.   


    Field[] fields = clazz.getDeclaredFields();for(Field field : fields) {
        PropertyDescriptor desc = new PropertyDescriptor(field.getName(), clazz);
        Method getMethod = desc.getReadMethod();
    }
    这样顺序就跟你定义的变量是一样的了
      

  5.   

    Field[] field = dtoClass.getFields();
    是按顺序的,昏啊。。
      

  6.   

    多谢楼上的,我也研究出来了,但是我dto里面是private方法。。很纠结阿。。
      

  7.   

    加一句这个就可以调用了
    getMethod.setAccessible(true);
      

  8.   

    哎,反射太不熟了,很多东西都不清楚。
    原来是这样的:
    getFields()方法:
    Returns an array containing <code>Field</code> objects reflecting all
    the accessible public fields of the class or interface represented by
    this <code>Class</code> object.getDeclaredFields()方法:
    Returns an array of <code>Field</code> objects reflecting all the fields
    declared by the class or interface represented by this
     <code>Class</code> object. This includes public, protected, default
     (package) access, and private fields, but excludes inherited fields.问题搞定了,多谢closewbq和lianfeng2478帮助,特别lianfeng2478,多谢了,结帖。