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"));
}
請確保清單數據= 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 /支柱/彈簧控制器
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>
返回空值,和我的數據庫中的表不是空的,即使有一個簡單的查詢Ÿ像「從Demande選擇date_demande」它給了我空值.. 謝謝你的答案btw! – user2420681
更新了答案 – Prabhakaran
是的,它返回的結果(data.size()= 16)它意味着它獲得的值,但仍然有null作爲結果,我想問題是在row.get(「....」) – user2420681