将List 对象转为对象中指定属性的 List 集合


List<AiPart> aiPartList = aiPartMapper.getAiPartsByCaseId(caseId);

        /**
         * 拼接成 List<InjuredReturnResult2>形式,一张图片对应哪几个配件。
         */
        List<InjuredReturnResult2> injuredReturnResult2List = new ArrayList<>();

        Map<String, List<AiPart>> groupBy2 = new HashMap<>();
        List<AiPart> tempList = null;
        for(AiPart aiPart : aiPartList ) {
            if(groupBy2.containsKey(aiPart.getImageUrl())) {
                tempList = groupBy2.get(aiPart.getImageUrl());
                tempList.add(aiPart);
            } else {
                // 否则,第一次先构造一个list,在存入map
                tempList = new ArrayList<>();
                tempList.add(aiPart);
                groupBy2.put(aiPart.getImageUrl(), tempList);
            }
        }
System.out.println("转换参数:"+JSON.toJSONString(groupBy2));

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM