0

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;
    }
  • 2
    Implement your comparator and sort your list with it. – Giorgi Tsiklauri Jul 28 '21 at 16:11
  • Could you give me a clue about it? if it was completed on internet before? my question is closed, but i couldnt find the answer. What should I change in this code, it orders by plate code, but i am expected to order it by city name –  Jul 28 '21 at 16:20
  • 1
    Take @Giorg iTsiklauri's comment, add java in front of it, and paste the comment in your favorite search engine. You should get plenty of hits. – Gilbert Le Blanc Jul 28 '21 at 18:30

0 Answers0