0
我是GAE的初學者,我的應用程序正在執行插入操作,但沒有從數據庫返回數據。日誌中不會顯示錯誤。 有什麼不對?從App Engine檢索數據
跟隨我的工廠類:
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class EMFService {
public static final EntityManagerFactory emfInstance =
Persistence.createEntityManagerFactory("transactions-optional");
private EMFService(){}
public static EntityManagerFactory get()
{
return emfInstance;
}
}
跟隨我的選擇類:
public List<Pessoa> listPessoas()
{
EntityManager em = EMFService.get().createEntityManager();
List<Pessoa> lista;
try
{
Query q = em.createQuery("select p from Pessoa p");
lista = (List<Pessoa>) q.getResultList();
}
finally
{
em.close();
}
return lista;
}
跟隨我的JSP頁面:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Pessoas</title>
</head>
<body>
<table border=1>
<thead>
<tr>
<th>Nome</th>
<th>Idade</th>
</tr>
</thead>
<tbody>
<c:forEach items="${pessoas}" var="pessoa">
<tr>
<td><c:out value="${pessoa.nome}" /></td>
<td><c:out value="${pessoa.idade}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
在你的模板中看你的案子。 「pessoa」應該是「Pessoa」 – GAEfan
除了代碼中的任何錯誤之外,如果您編寫實體並立即查詢它,它可能不會顯示一段時間。閱讀最終的一致性。 –