public Map<Integer,String> getCity(List<Integer> cityIds) throws Exception{ Map<Integer,String> cityNames = new LinkedHashMap<>(); List<CityMapping> citys = this.getAllCity(); for(Integer cityId : cityIds) { Optional<CityMapping> cityItem = citys.stream().filter(x -> x.getCityId().equals(cityId) ).findFirst(); if(cityItem.isPresent()){ cityNames.put(cityId,cityItem.get().getCityName()); } } return cityNames; }
Optional
时间: 2024-10-04 23:48:22