Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- |--------|------------|
- | City | CountryId |
- |--------|------------|
- public List<CityModel> selectAll() throws Exception {
- List<CityModel> cities = new ArrayList<>();
- String selectCities = "select * from cities inner join countries on countries.id = cities.countryId";
- // ... create city and country model in the same query
- return cities;
- }
- public List<CityModel> selectAll() throws Exception {
- List<CityModel> cities = new ArrayList<>();
- String selectCities = "select * from cities";
- // ... create get cities model from table and add them to cities
- foreach(City city in cities)
- {
- String selectCountry = "select * from countries where id = " + city.getCountryId();
- // ... create country model
- city.setCountry(country)
- }
- ...
- return cities;
- }
Add Comment
Please, Sign In to add comment