resultSet2Bean

	public List<T> resultSet2Bean(ResultSet rs,Class<T> cls){
		List<T> lists = new ArrayList<T>();
		T bean = null;
		try {
			ResultSetMetaData rsmd = rs.getMetaData();
			int cols = rsmd.getColumnCount();
			while(rs.next()){
				bean = cls.newInstance();
				for (int i = 0; i < cols; i++) {
					String elename = rsmd.getColumnName(i+1);
					Method getele = cls.getMethod("get"+elename);
					Method setele = cls.getMethod("set" +elename,getele.getReturnType());
					String value = rs.getString(i+1);
					setele.invoke(bean, value);
				}
				lists.add(bean);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return lists;
	}
相关文章
相关标签/搜索