Guest User

Untitled

a guest
Nov 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. |--------|------------|
  2. | City | CountryId |
  3. |--------|------------|
  4.  
  5. public List<CityModel> selectAll() throws Exception {
  6. List<CityModel> cities = new ArrayList<>();
  7.  
  8. String selectCities = "select * from cities inner join countries on countries.id = cities.countryId";
  9.  
  10. // ... create city and country model in the same query
  11.  
  12. return cities;
  13. }
  14.  
  15. public List<CityModel> selectAll() throws Exception {
  16. List<CityModel> cities = new ArrayList<>();
  17.  
  18. String selectCities = "select * from cities";
  19. // ... create get cities model from table and add them to cities
  20. foreach(City city in cities)
  21. {
  22. String selectCountry = "select * from countries where id = " + city.getCountryId();
  23. // ... create country model
  24. city.setCountry(country)
  25. }
  26. ...
  27. return cities;
  28. }
Add Comment
Please, Sign In to add comment