activiti Stream之list转map及问题解决

该篇博客展示了如何利用Java 8的Stream API中的Collectors.toMap方法,将List<ProcessDefinition>转换成List<Map<String, String>>。具体操作是在List中遍历每个元素,创建一个新的Map并填充属性,然后收集到一个List中,最后设置到TableDataInfo对象中,用于数据展示。
摘要由CSDN通过智能技术生成

List集合转Map,用到的是Stream中Collectors的toMap方法:Collectors.toMap
具体用法实例如下:

    public TableDataInfo modelList(Integer pageNum, Integer pageSize){
    TableDataInfo tableDataInfo = new TableDataInfo();
    Long count = repositoryService.createProcessDefinitionQuery().count();
        List <ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery()
                .latestVersion()
                .listPage(pageNum-1,pageSize);
        List<Map<String,String>> list= processDefinitionList.stream().map( (s)-> {
            Map<String,String> map = new HashMap <>();
            map.put("name",s.getName());
            map.put("des",s.getDescription());
            map.put("version",String.valueOf(s.getVersion()));
            map.put("key",s.getKey());
            map.put("id",s.getId());
            return map;
        }).collect(Collectors.toList());
                tableDataInfo.setRows(list);
                tableDataInfo.setTotal(count);
        return tableDataInfo;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值