java实现jdbc查询结果集result转换成对应list集合
程序员文章站
2024-03-07 22:29:27
代码非常的简单,这里就不多废话了,直接奉上
public static list converttolist(results...
代码非常的简单,这里就不多废话了,直接奉上
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; }
是不是很简单。。给新手参考下的,老鸟们请略过