用Map消除为字典匹配的双重for循环

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

 

你可能感兴趣的:(用Map消除为字典匹配的双重for循环)