用Lists.transform返回多个List
List<String> realNames = Lists.transform(applys, a -> {
String realName = a.getRealName();
if (StringUtils.isNotEmpty(realName)) {
StringBuilder stringBuilder = new StringBuilder(realName);
realName = stringBuilder.replace(1, stringBuilder.length(), "*").toString();
}
return realName;
}).stream().filter(a -> StringUtils.isNotEmpty(a)).distinct().collect(Collectors.toList());
java中一对多的关系 取出
public BaseResponseVo<List<FeedBackVo>> query(FeedBackQo feedBackQo) {
PageHelper.startPage(feedBackQo.getPage(), feedBackQo.getLimit());
List<FeedBackVo> feedBackVos = feedBackMapper.query(feedBackQo);
PageInfo<FeedBackVo> pageInfo = new PageInfo<>(feedBackVos);
List<FeedBackVo> feedBackVoList = new ArrayList<>();
if (feedBackVos.size() > 0) {
// 取出所有的Id
List<String> imgSpecs = Lists.transform(feedBackVos, t -> t.getId());
// 根据Id和类型查询图片
List<ImgEntity> imgEntities = imgMapper.queryByTypeAndBizids(TransactionType.FEEDBACK.getType(), imgSpecs);
// 根据BizId分组
Map<String, List<ImgEntity>> imgMaps = imgEntities.stream().collect(Collectors.groupingBy(i -> i.getBizId()));
for (int i = 0; i < feedBackVos.size(); i++) {
FeedBackVo feedBackVo1 = feedBackVos.get(i);
if (imgMaps != null && imgMaps.get(feedBackVo1.getId()) != null) {
List<String> imgUrls = Lists.transform(imgMaps.get(feedBackVo1.getId()), t -> t.getUrl());
feedBackVo1.setImgList(imgUrls);
}
feedBackVoList.add(feedBackVo1);
}
}
return BaseResponseVo.succ(pageInfo.getTotal(), feedBackVoList);
}
今天的文章java 运用Lists分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/6214.html