前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Stream与函数式编程

Stream与函数式编程

原创
作者头像
在下是首席架构师
发布2024-07-24 10:18:40
370
发布2024-07-24 10:18:40
举报
文章被收录于专栏:从入门到出门

场景

mysql通过union,查询出了多种类型和数量,需要放入vo字段里展示给前端

代码语言:java
复制
    @Override
    public FollowUpVisitVO followUpVisit(String date) {
        
        FollowUpVisitVO followUpVisitVO = new FollowUpVisitVO();
        followUpVisitVO.setCreateName(user.getNickName());

        List<StringTypeNumsVO> typeNumsVos = mapper.queryList(SecurityUtils.getUserId(), date);

        findTypeNums(typeNumsVos, "zrhftx", followUpVisitVO, FollowUpVisitVO::setZrhftx);
        findTypeNums(typeNumsVos, "jrhfxt", followUpVisitVO, FollowUpVisitVO::setJthftx);
        findTypeNums(typeNumsVos, "qqttx", followUpVisitVO, FollowUpVisitVO::setQqttx);
        findTypeNums(typeNumsVos, "wlx7", followUpVisitVO, FollowUpVisitVO::setWlx7);
        findTypeNums(typeNumsVos, "wlx815", followUpVisitVO, FollowUpVisitVO::setWlx815);
        findTypeNums(typeNumsVos, "dy7", followUpVisitVO, FollowUpVisitVO::setDy7);
        findTypeNums(typeNumsVos, "dy815", followUpVisitVO, FollowUpVisitVO::setDy815);
        findTypeNums(typeNumsVos, "dy1630", followUpVisitVO, FollowUpVisitVO::setDy1630);
        findTypeNums(typeNumsVos, "ss7", followUpVisitVO, FollowUpVisitVO::setSs7);

        return followUpVisitVO;
    }
    
    
    
    private void findTypeNums(List<StringTypeNumsVO> typeNumsVos, String type,
                                FollowUpVisitVO followUpVisitVO,
                                KeyValueStreamingChannel<FollowUpVisitVO, Integer> setNums) {
        typeNumsVos.stream()
                .filter(x -> type.equals(x.getType()))
                .findFirst()
                .ifPresent(x -> setNums.onKeyValue(followUpVisitVO, x.getNums()));
    }

其他解决方法

mysql的行转列,可以直接将结果放入vo字段

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 场景
  • 其他解决方法
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档