日期:2014-05-20 浏览次数:21026 次
/**
* @param <T>
* @param dataList 对象集合
* @param T 对象
* @param tAttrs 对象属性集合
*/
public <T> void saveList(List<T> dataList, Class<T> T, List<String> tAttrs) {
try {
if (dataList != null && dataList.size() >0) {
for (int i = 0; i < dataList.size(); i++) {
if (tAttrs != null && tAttrs.size() != 0) {
for (String attr : tAttrs) {
String methodName = "get" + attr.substring(0, 1).toUpperCase() + attr.substring(1);
Method method = T.getMethod(methodName);
Object obj = method.invoke(dataList.get(i));
System.out.println(obj);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
------解决方案--------------------
我觉得楼主需要的可能是 这个 Joda-Convert provides a small set of classes to aid conversion between Objects and Strings. It is not intended to tackle the wider problem of Object to Object transformation.