通过sql获取到的结果为hash列,项目需要.
功能:将结果集合反射并构造出新实体返回
public static <T> T builFromRet(T clazz,Vector ret){
Map<String, Object> map;
Method m = null;
T t = null;
try {
t = (T) clazz.getClass().newInstance();
if(ret == null || ret.size() < 1){
return t;
}
map = (Map<String, Object>) ret.get(0);
for(Map.Entry<String, Object> entry : map.entrySet())
{
m = t.getClass().getDeclaredMethod("set"+entry.getKey(),String.class);
m.setAccessible(true);
m.invoke(t, entry.getValue());
// System.out.println("private String "+entry.getKey());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return t;
}
return t;
}