This is written in Java. It works perfectly. But it writes cities based on their plate code from 1 to 80 for example. But city names for example 1- ZCity, 2-ACity, so it is not what I want.
What should I change in this code to produce cities by their name(letters)
Here is the code:
@RequestMapping(value = "/getCities", method = RequestMethod.GET)
@Cacheable("cities")
public @ResponseBody List<KeyValueDTO> getCities() {
logger.trace("getCities begins.");
List<City> cityList = cityService.findAll();
List<KeyValueDTO> cityKeyDtoList = new ArrayList<>();
for (City city : cityList) {
KeyValueDTO cityKeyDto = new KeyValueDTO();
cityKeyDto.setKey(city.getName());
cityKeyDto.setValue(String.valueOf(city.getCode()));
cityKeyDtoList.add(cityKeyDto);
}
logger.trace("CityController: getAllCities ends");
return cityKeyDtoList;
}