String squery="select date_demande as {d.date_demande},nom as {c.nom}, prénom as {c.prénom} from Demande d , Candidat c
where d.id_candidat=c.id_candidat";
SQLQuery query=session.createSQLQuery(squery);
query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
Map<String,Object> row = null;
List data = query.list();
for (Object object : data) {
row= (Map<String,Object>)object;
System.out.println("date_demande: " + row.get("date_demande"));
System.out.println("nom: " + row.get("nom"));
System.out.println("prénom: " + row.get("prénom"));
}
请确保 List data = query.list(); 返回结果。
更新
迭代地图并查看值和键并在此基础上工作。
for (Object object : data) {
Map row = (Map) object;
Iterator entries = row.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
System.out.println("Key = " + key + ", Value = " + entry.getValue());
}
}
或者
for (Object object : data) {
Map row = (Map) object;
System.out.print(row.get("0"));
System.out.print("\t" + row.get("1"));
System.out.print("\t" + row.get("2"));
}
把它写在你的 servlet/struts/spring 控制器中
request.setAttribute("list", data);
把这个写在你的jsp中
<c:forEach items="${list}" var="map">
<c:forEach items="${map}" var="entry">
${entry.key}<br>
${entry.value}<br>
</c:forEach>
</c:forEach>