代码非常的简单,这里就不多废话了,直接奉上
public static List convertToList(ResultSet rs,Class t) throws SQLException { List> list = new ArrayList>(); ResultSetMetaData md = (ResultSetMetaData) rs.getMetaData(); int columnCount = md.getColumnCount(); while (rs.next()) { Map rowData = new HashMap(); for (int i = 1; i <= columnCount; i++) { rowData.put(md.getColumnName(i), rs.getObject(i)); } list.add(rowData); } JSONArray jr = JSONArray.fromObject(list); List resultList = JSONArray.toList(jr, t); return resultList; }
是不是很简单。。给新手参考下的,老鸟们请略过