ORM小工具
代码:
package org.blueidea.tools;
import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.beanutils.BeanUtils;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
* ResultSetMetaData 可用于获取关于 ResultSet 对象中列的类型和属性信息的对象
* ResultSet.getMetaData() 检索此 ResultSet 对象的列的编号、类型和属性
*/
public class DTOPopulator {
public static List populate(ResultSet rs,Class clazz) throws Exception{
ResultSetMetaData metaData = rs.getMetaData();
int colCount = metaData.getColumnCount();
List ret = new ArrayList();
Field[] fields = clazz.getDeclaredFields();
while(rs.next()){
Object newInstance = clazz.newInstance();
for(int i=1;i<=colCount;i++){
try{
Object value = rs.getObject(i);
for(int j=0;j
Field f = fields[j];
if(f.getName().equalsIgnoreCase(metaData.getColumnName(i).replaceAll("_","")))
{
BeanUtils.copyProperty(newInstance,f.getName(),value);
}
}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
ret.add(newInstance);
}
return ret;
}
}
uc浏览器网页版入口官网-手机/电脑uc浏览器网页版入口地址
little fox官方网站入口地址-little fox网页版中国官网入口地址
樱花动漫网官网在线观看入口-樱花动漫网最新网页版入口地址2026
剑桥少儿英语官网入口网址-剑桥少儿英语网页版入口地址
手机百度网盘登录入口地址-百度网盘手机网页版登录入口地址
192.168.1.1无线路由怎么访问?192.168.1.1无线路由器设置登录入口地址