Designing the CityDAO

The following are some of the important operations to be supported by com.nilangpatel.worldgdp.dao.CityDAO class:

  • Get cities for a country
  • Get city details for given ID
  • Add a new city to a country
  • Delete the given city from the country

Let's go ahead and implement each one of these functionalities starting with the getCities, as follows:

public List<City> getCities(String countryCode, Integer pageNo){  Map<String, Object> params = new HashMap<String, Object>();  params.put("code", countryCode);  if ( pageNo != null ) {    Integer offset = (pageNo - 1) * PAGE_SIZE;    params.put("offset", offset);    params.put("size", PAGE_SIZE);  }    return namedParamJdbcTemplate.query("SELECT " + " id, name, countrycode country_code, district, ...

Get Spring 5.0 Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.