答案 0 :(得分:0)
这是yourNameFacadeREST
应如何显示的示例:
@GET
@Override
@Produces({"application/xml", "application/json"})
public List<ExampleTable> testFindByName() {
List<ExampleTable> results = em.createNamedQuery("ExampleTable.findByName", ExampleTable.class)
.setParameter("firstname", 1)
.setParameter("lastname", 1)
.getResultList();
return results;
}
@GET
@Path("test")
@Produces(MediaType.TEXT_HTML)
public void findName(
@Context final HttpServletRequest request,
@Context final HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/foundbyname.jsp");
request.setAttribute("items", testFindByName());
dispatcher.forward(request, response);
}
不要忘记将@NamedQuery更改为(如下例所示):
@NamedQuery(name = "ExampleTable.findByName", query = "SELECT e FROM ExampleTable e WHERE e.firstname = :firstname AND e.lastname = :lastname")
这将找到名字为&#34; 1&#34;的行。和姓氏&#34; 1&#34;。
要在JSP中显示它,您现在可以使用例如:
<c:forEach items="${items}" var="item">
然后:
<p>firstname: ${item.firstname}</p>
根据您的需要当然。