加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何迭代嵌套列表

发布时间:2020-12-15 08:43:07 所属栏目:Java 来源:网络整理
导读:嗨,我有一个hibernate查询,它给我一个类型为List List integer的列表. 我怎么能迭代这个?我的hibernate查询是: String SQL_QUERY = "select DISTINCT cbl.franchiseId,cbl.resellerId from CustomerBusinessLocation cbl where cbl.cmcustLocId in (:locat
嗨,我有一个hibernate查询,它给我一个类型为List< List< integer>>的列表.
我怎么能迭代这个?我的hibernate查询是:

String SQL_QUERY = "select DISTINCT cbl.franchiseId,cbl.resellerId from 
     CustomerBusinessLocation cbl where cbl.cmcustLocId in (:locationId)";

Query query = getSession().createQuery(SQL_QUERY); 

query.setParameterList("locationId",customerLocId);

List<List<Integer>> rc_list = query.list();

或者,有没有其他方法可以轻松提取这些数据?

解决方法

此查询不返回List< List< Integer>>.它返回List< Object []>. Object []数组每个请求的字段包含一个元素.在您的情况下,每个Object []将包含索引0处的franchiseId和索引1处的resellerId.

这当然在the reference documentation中解释.

因此迭代应如下所示:

List<Object[]> rows = query.list();
for (Object[] row : rows) {
    Integer franchiseId = (Integer) row[0];
    Integer resellerId = (Integer) row[1];
    // ...
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读