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;
}

}

相关文章:

  • 2021-06-08
  • 2021-12-18
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-12-19
  • 2021-10-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2021-05-01
相关资源
相似解决方案