代码非常的简单,这里就不多废话了,直接奉上
public static <T> List<T> convertToList(ResultSet rs,Class<T> t) throws SQLException { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); ResultSetMetaData md = (ResultSetMetaData) rs.getMetaData(); int columnCount = md.getColumnCount(); while (rs.next()) { Map<String, Object> rowData = new HashMap<String, Object>(); for (int i = 1; i <= columnCount; i++) { rowData.put(md.getColumnName(i), rs.getObject(i)); } list.add(rowData); } JSONArray jr = JSONArray.fromObject(list); List<T> resultList = JSONArray.toList(jr, t); return resultList; }
是不是很简单。。给新手参考下的,老鸟们请略过
本文地址:https://www.stayed.cn/item/6314
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我