將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