Alguem poderia me ajudar como eu mostro o resultado de uma consulta inner join em uma view no Spring. Como eu faço para retornar todos os campos de todas as tabelas do inner join e mostrar na view??
Trecho da classe modelo:
Trecho do DAO:
public List buscarTodosAgendamentos() {
String sql = “SELECT * FROM bAgendamento AS agendamento INNER JOIN bsDestino AS destino”
+ " ON agendamento.idDestinoAgendamento = destino.idDestino INNER JOIN"
+ " bsMotorista AS motorista ON agendamento.idMotoristaAgendamento = motorista.idMotorista "
+ " INNER JOIN bsAutomovel AS automovel ON agendamento.idAutomovelAgendamento = “
+ " automovel.idAutomovel INNER JOIN bsRota AS rota ON agendamento.idRotaAgendamento =”
+ " rota.idRota ORDER BY agendamento.dataSolicitacaoPacAPP ASC ";
List list = namedParameterJdbcTemplate.query(sql,getSqlParameterByModel(null),
new AgendamentoMapper());
return list;
}
Trecho da VIew (Quero retornar os campos do objeto Destino, Automovel…) :
segundo o link: http://javatechnology.net/spring/select-join-rowmapper/
public class Site {
private Integer siteId;
private String siteName;
private Integer categoryId;
public Integer getSiteId() {
return siteId;
}
public void setSiteId(Integer siteId) {
this.siteId = siteId;
}
public String getSiteName() {
return siteName;
}
public void setSiteName(String siteName) {
this.siteName = siteName;
}
public Integer getCategoryId() {
return categoryId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
}
public class Category {
private Integer categoryId;
private String categoryName;
public Integer getCategoryId() {
return categoryId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
}
@Component
public class SiteJoinCategoryDao {
@Resource
private JdbcTemplate jdbcTemplate;
public List<SiteJoinCategory> findAll() {
String sql = "select site.*, cat.* " +
"from t_site site inner join m_category cat " +
"ON site.category_id = cat.category_id";
RowMapper<SiteJoinCategory> rowMapper = new SiteCategoryRowMapper();
List<SiteJoinCategory> list = jdbcTemplate.query(sql, rowMapper);
return list;
}
/**
* RowMapper
*/
protected class SiteCategoryRowMapper implements RowMapper<SiteJoinCategory> {
@Override
public SiteJoinCategory mapRow(ResultSet rs, int rowNum) throws SQLException {
SiteJoinCategory siteJoinCategory = new SiteJoinCategory();
Site site = new Site();
Category category = new Category();
site.setSiteId(rs.getInt("site.site_id"));
site.setSiteName(rs.getString("site.site_name"));
site.setCategoryId(rs.getInt("site.category_id"));
category.setCategoryId(rs.getInt("cat.category_id"));
category.setCategoryName(rs.getString("cat.category_name"));
siteJoinCategory.setSite(site);
siteJoinCategory.setCategory(category);
return siteJoinCategory;
}
}
}
View (exemplo: