public static List<Book> creatFinanceXObj(List list) throws Exception {
List<Book> financeEntityList = new ArrayList<Book>();
Class<Book> type = com.winit.entity.Book.class;
Book sellFinanceEntity = null;
Field[] Fields = type.getDeclaredFields();
for (int i = 0; i < list.size(); i++) {
Object[] obj = (Object[]) list.get(i);
sellFinanceEntity = type.newInstance();
for (int j = 0; j < obj.length; j++) {
String temp = Fields[j].getName();
String methodName = (temp.charAt(0) + "").toUpperCase()
+ temp.substring(1, temp.length());
if (j == obj.length - 1) {
Method method = type.getMethod("set" + methodName,
new Class[] { String.class });
method.invoke(sellFinanceEntity, obj[j]);
} else {
Method method = type.getMethod("set" + methodName,
new Class[] { Double.class });
method.invoke(sellFinanceEntity,
Double.parseDouble(obj[j] + ""));
}
}
financeEntityList.add(sellFinanceEntity);
}
return financeEntityList;
}
以下代码只作为笔记参考,不要误解。