/*** Document转化为class
*
* @Title: getObject
*@paramdoc
*@paramcls
*@return*@authorlihui
*@param
*@throwsException
*@throwsSecurityException
*@throwsNoSuchMethodException
* @date 2015年9月18日 下午1:18:29*/
public static void getObject(Document doc, T cls) throwsNoSuchMethodException, SecurityException, Exception {
Field fd[]=cls.getClass().getDeclaredFields();
Object object=cls;for(Field field : fd) {
System.out.println(field.getGenericType().toString());
Object value=doc.get(field.getName());if (value != null && !value.toString().equals("")) {
PropertyDescriptor pd= newPropertyDescriptor(field.getName(), cls.getClass());
Method m= pd.getWriteMethod();//获得写方法
if (field.getGenericType().toString().equals("class java.lang.String")) {
m.invoke(object, value.toString());
}else if (field.getGenericType().toString().equals("class java.lang.Integer")) {
m.invoke(object, Integer.valueOf(value.toString()));
}else if (field.getGenericType().toString().equals("class java.lang.Double")) {
m.invoke(object, Double.valueOf(value.toString()));
}else if (field.getGenericType().toString().equals("class java.lang.Long")) {
m.invoke(object, Long.valueOf(value.toString()));
}else if (field.getGenericType().toString().equals("class java.lang.Boolean")) {
m.invoke(object, Boolean.valueOf(value.toString()));
}else if (field.getGenericType().toString().equals("class java.util.Date")) {
SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
m.invoke(object, df.parse(value.toString()));
}
}
}
}