标签:
class BeanHandler<T> implements ResultSetHandler<T>{
private Class<T> clazz;
public BeanHandler(Class<T> clazz){
this.clazz=clazz;
}
public T handle(ResultSet rs) throws SQLException {
T t=clazz.newInstance();
while(rs.next()){
Field[] fields = clazz.getDeclaredFields();
for(Field f:fields){
String columnName=f.getAnnotation(Column.class).column();
Object columnValue=rs.getObject(columnName);
String fieldName=f.getName();
BeanUtils.copyProperty(t, fieldName, columnValue);
}
}
return t;
}
}
标签:
原文地址:http://www.cnblogs.com/ly-china/p/5437212.html