用Map消除爲字典匹配的雙重for循環

        //獲取數據
        List<Student> studentList = studentMapper.select();
        //獲取字典code、name
        List<Dic> dicList = dicMapper.selectDicList();
        //字典放入map
        Map<String, String> dicMap = new HashMap<>();
        for (Dic dicDto : dicList) {
            dicMap.put(dicDto.getCode(), dicDto.getName());
        }
        //匹配數據
        for(Student stuDto:studentList){
            stuDto.setSexStr(dicMap.get(stuDto.getSex()));
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章