mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
#92 Use column alias
This commit is contained in:
parent
91d19d17b8
commit
06be7eb5be
3 changed files with 3 additions and 3 deletions
|
@ -110,7 +110,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", owner.getId());
|
||||
final List<JdbcPet> pets = this.namedParameterJdbcTemplate.query(
|
||||
"SELECT pets.id, name, birth_date, type_id, owner_id, visits.id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id",
|
||||
"SELECT pets.id, name, birth_date, type_id, owner_id, visits.id as visit_id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id",
|
||||
params,
|
||||
new JdbcPetVisitExtractor()
|
||||
);
|
||||
|
|
|
@ -81,7 +81,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
|
|||
@Override
|
||||
public List<Visit> findByPetId(Integer petId) {
|
||||
return this.jdbcTemplate.query(
|
||||
"SELECT id, visit_date, description FROM visits WHERE pet_id=?",
|
||||
"SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=?",
|
||||
new JdbcVisitRowMapper(), petId);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class JdbcVisitRowMapper implements RowMapper<Visit> {
|
|||
@Override
|
||||
public Visit mapRow(ResultSet rs, int row) throws SQLException {
|
||||
Visit visit = new Visit();
|
||||
visit.setId(rs.getInt("id"));
|
||||
visit.setId(rs.getInt("visit_id"));
|
||||
Date visitDate = rs.getDate("visit_date");
|
||||
visit.setDate(new DateTime(visitDate));
|
||||
visit.setDescription(rs.getString("description"));
|
||||
|
|
Loading…
Reference in a new issue