public class BeanProperty {
private static final String FILTER_REG = "serialVersionUID";
public static List<?> arrayCastBean(String dir,List<Object[]> list) {
List<Object> result = new ArrayList<Object>();
boolean flag = false;
try {
Class<?> clazz = Class.forName(dir);
Object obj = null;
Field[] fields = clazz.getDeclaredFields();
if(fields[0].getName().equals(BeanProperty.FILTER_REG)){
flag = true;
}
for(Object[] values : list){
obj = clazz.newInstance();
for(int i=0;i<fields.length;i++){
if(!fields[i].getName().equals(BeanProperty.FILTER_REG)){
PropertyDescriptor pd = new PropertyDescriptor(fields[i].getName(), clazz);
Method m = pd.getWriteMethod();
m.invoke(obj, values[flag?(i-1):i]==null?"":values[flag?(i-1):i].toString());
}
}
result.add(obj);
}
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e2) {
e2.printStackTrace();
} catch (InstantiationException e3) {
e3.printStackTrace();
} catch (IllegalArgumentException e6) {
e6.printStackTrace();
} catch (IntrospectionException e4) {
e4.printStackTrace();
} catch (InvocationTargetException e5) {
e5.printStackTrace();
}
return result;
}
最后将返回的list强转成你传的地址的javabean就可以了